Using pytest-dependency to solve the problem of dependency between use cases
Usage scenario: test B can be effectively carried out only after Test A has passed successfully.
Use this plug-in to mark a test as a dependency on other test, and those test that depend on it will be skipped when the execution of the dependency fails.
-example above:
Installation: pytest-dependency
Pip install pytest-dependency
Use:
Import pytest@pytest.mark.dependency () def test_01 (test): assert False@pytest.mark.dependency (depends= ["test_01"]) def test_02 (test): print ("execute Test 2")
Take a look at the results:
Test_01 is a dependency of test_02, so after test_01 fails, test_02 is skipped
Conclusion:
1. Install the plug-in first
2. The way to use it is to mark the dependent method with @ pytest.mark.dependency () and use @ pytest.mark.dependency (depends= ["test_name"]) to refer to the dependency.