Skip to content

Better report doubles.verify failures in pytest #131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions doubles/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

from doubles.lifecycle import teardown, verify

def pytest_runtest_call(item):
def verify_and_teardown_doubles():
try:
verify()
finally:
teardown()
@pytest.hookimpl(hookwrapper=True)
def pytest_pyfunc_call(pyfuncitem):
outcome = yield

item.addfinalizer(verify_and_teardown_doubles)
try:
outcome.get_result()
verify()
finally:
teardown()
5 changes: 1 addition & 4 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
cov = coverage(source=('doubles',))
cov.start()

try:
from doubles.pytest_plugin import pytest_runtest_protocol # noqa
except ImportError:
from doubles.pytest_plugin import pytest_runtest_call # noqa
pytest_plugins = ['doubles.pytest_plugin']


def pytest_sessionfinish(session, exitstatus):
Expand Down
2 changes: 1 addition & 1 deletion test/pytest_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_that_should_fail_for_not_satisfying_expection():
""")
result = testdir.runpytest()
outcomes = result.parseoutcomes()
assert outcomes['error'] == 2
assert outcomes['failed'] == 2
expected_error = (
"*Expected 'class_method' to be called 1 time instead of 0 times on"
" <class 'doubles.testing.User'> with ('{arg_value}')*"
Expand Down