Skip to content

Rerunning skipped cases when the parent test fails #74

@sramasub

Description

@sramasub

I have the following code:

_import pytest, pytest_dependency, pytest_order

@pytest.mark.order(1)
@pytest.mark.dependency(name="1")
def test_1():
assert 1==1

@pytest.mark.order(2)
@pytest.mark.dependency(name="2", depends="1")
def test_2():
assert 1==1

@pytest.mark.order(3)
@pytest.mark.dependency(name="3", depends="2")
def test_3():
assert 1==1

@pytest.mark.order(4)
@pytest.mark.dependency(name="4", depends="3")
def test_4():
assert 1==1_

All the above runs in the defined order when they pass.

Now lets's say test_2() fails:

_============================= test session starts =============================
collecting ... collected 4 items

randomTests.py::test_1 PASSED [ 25%]
randomTests.py::test_2 FAILED [ 50%]
randomTests.py:7 (test_2)
1 != 2

Expected :2
Actual :1

@pytest.mark.order(2)
@pytest.mark.dependency(name="2", depends="1")
def test_2():

  assert 1==2

E assert 1 == 2

randomTests.py:11: AssertionError

randomTests.py::test_3 SKIPPED (test_3 depends on 2) [ 75%]
Skipped: test_3 depends on 2

randomTests.py::test_4 SKIPPED (test_4 depends on 3) [100%]
Skipped: test_4 depends on 3

=================== 1 failed, 1 passed, 2 skipped in 0.56s ====================_

Tests 3 and 4 are skipped because test_3 depends on test_2 and test_4 depends on test_3. Now i rectify test_2 to fix the problem and rerun the failed case using the 'last failed' parameter.

_============================= test session starts =============================
collecting ... collected 4 items / 3 deselected / 1 selected
run-last-failure: rerun previous 1 failure

randomTests.py::test_2 SKIPPED (test_2 depends on 1) [100%]
Skipped: test_2 depends on 1

====================== 1 skipped, 3 deselected in 0.03s =======================_

Only test 2 runs. I want test3 and test4 to be also picked because they were unable to run last time. Is there any way to achieve this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions