Hi Ramesh, Pytest provides an Incremental Marker which can be used to mark all dependent tests which are as expected to fail, so they don’t get executed. So, if you have 2 tests i.e. Test1 and Test2 in a test class and Test2 depends on Test1. So in case Test1 fails, Test2 would be executed unnecessarily. So to avoid such executions, we use Incremental Marker and the tests executed using marker are called as Incremental Testing. You can use following lines of code in confttest.py:
def pytest_runtest_makereport(item, call):
if "incremental" in item.keywords:
if call.excinfo is not None:
parent = item.parent
parent._previousfailed = item
def pytest_runtest_setup(item):
if "incremental" in item.keywords:
previousfailed = getattr(item.parent, "_previousfailed", None)
if previousfailed is not None:
pytest.xfail("previous test failed (%s)" %previousfailed.name)
Mark the test class with the @pytest.mark.incremental as shown below:
@pytest.mark.incremental
class TestBooking(BaseTest)
This will result in marking Test1 as Failed, while marking Test2 as Expected to Fail (xfailed)