Created
November 14, 2013 21:37
-
-
Save jlaska/7474758 to your computer and use it in GitHub Desktop.
Pytest plugin to enable test scenarios. A test scenario is a series of related tests where sequential successful execution is important.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import py | |
import pytest | |
''' | |
Automatically xfail remaining tests if previous test failed. Tests will | |
continue to run if: | |
* the result is skip | |
* the result is xfail | |
* the test is marked as nondestructive | |
For more information, refer to | |
http://stackoverflow.com/questions/12411431/pytest-how-to-skip-the-rest-of-tests-in-the-class-if-one-has-failed/12579625#12579625 | |
''' | |
def pytest_runtest_makereport(item, call): | |
if "incremental" in item.keywords \ | |
and "destructive" in item.keywords \ | |
and call.excinfo is not None \ | |
and not any([call.excinfo.errisinstance(py.test.xfail.Exception), | |
call.excinfo.errisinstance(py.test.skip.Exception)]): | |
parent = item.parent | |
parent._previousfailed = item | |
def pytest_runtest_setup(item): | |
previousfailed = getattr(item.parent, "_previousfailed", None) | |
if previousfailed is not None: | |
pytest.xfail("previous test failed (%s)" %previousfailed.name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for sharing, exactly what I was looking for. One hint:
does the trick and is easier to read. It's a simple instance check, which also accepts tuples of several types in question.