如何在pytest中运行两次测试

时间:2017-09-20 09:11:32

标签: python-2.7 pytest

我在模块中有三个测试

def test_A(fixture, test_param): 
def test_B(fixture, test_param):
def test_c(fixture, test_param):

我需要按以下顺序运行测试:

def test_A()
def test_C()
def test_B()
def test_C()

test_C()应该在test_A()之后和test_B()之后运行两次。 我标记了

@pytest.mark.run(after='test_A')
@pytest.mark.run(after='test_B')
def test_C()

test_c()仅在test_A()Test_B()之后。{/ p>

1 个答案:

答案 0 :(得分:1)

test_C分解出来并以不同的名称运行两次:

def _test_C():
    …code for test C…

def test_A():
    …

def test_C()
    _test_C()

def test_B()
    …

def test_C2()
    _test_C()