Created
September 4, 2014 10:18
-
-
Save shauns/a5728deeb411a51d0f19 to your computer and use it in GitHub Desktop.
Tracking pytest errors
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 pytest | |
def track_test_fails(): | |
@pytest.mark.tryfirst | |
def pytest_runtest_makereport(item, call, __multicall__): | |
# execute all other hooks to obtain the report object | |
rep = __multicall__.execute() | |
# `when` is setup, call, teardown | |
setattr(item, "rep_" + rep.when, rep) | |
# mark failures explicitly | |
if hasattr(item, 'rep_setup') and hasattr(item, 'rep_call'): | |
item.test_failed = ( | |
item.rep_setup.passed and item.rep_call.failed | |
) | |
return rep | |
return pytest_runtest_makereport | |
pytest_runtest_makereport = track_test_fails() | |
@pytest.yield_fixture | |
def foo(request): | |
if pytest.config.option.skip_foo: | |
pytest.skip('Foo tests are skipped') | |
if not platform.config.get('foo_uri'): | |
pytest.fail( | |
'Please configure foo uri or skip with ...' | |
) | |
yield | |
if request.node.test_failed: | |
pytest.fail( | |
"Maybe your test failed because X, Y, Z or you can skip with ..." | |
) | |
def test_foo(foo): | |
assert False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment