sramise
sramise

Reputation: 11

How to run a test twice in pytest

I have three tests in a module

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

I have a requirement to run the test in following order:

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

test_C() should run two times, after test_A() and also after test_B(). I have marked

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

but test_c() is only once after test_A() or Test_B().

Upvotes: 1

Views: 405

Answers (1)

phd
phd

Reputation: 94397

Factor out test_C and run it twice under different names:

def _test_C():
    …code for test C…

def test_A():
    …

def test_C()
    _test_C()

def test_B()
    …

def test_C2()
    _test_C()

Upvotes: 1

Related Questions