Say if Appium throws a webdriver exception error, only then that specific test should rerun in pytest.
1 Answer
Use the pytest-rerunfailures library to achieve this. It is a plugin for pytest.
Following are the requirements to use it.
Python 3.6, up to 3.8, or PyPy 3
pytest 5.0 or newer
Once installed, you can pass --only-rerun argument with pytest and rerun the specific failed test.
pytest --reruns 5 --only-rerun AssertionError
pytest --lfwill rerun all tests that failed in the previous run (lf= "last failed").pytest --lf -xwill rerun only the first test that has failed in the previous run. If you want to run a specific test, pass its node ID as parameter, e.g.pytest tests/test_module.py::test_func_name. The node IDs of the failed tests are printed in a special section at the end of the output.--lf(an alias of--last-failed) is documented in How to rerun failed tests and maintain state between test runs. See also this answer.