Skip to content
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

Fixed issue shadowing error when missing argument on teardown_method #1605

Merged
merged 1 commit into from
Jun 12, 2016
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
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,4 @@ Thomas Grainger
Tom Viner
Trevor Bekolay
Wouter van Ackooy
Bernard Pratz
4 changes: 3 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
* Text documents without any doctests no longer appear as "skipped".
Thanks `@graingert`_ for reporting and providing a full PR (`#1580`_).

*
* Fix internal error issue when ``method`` argument is missing for
``teardown_method()``. Fixes (`#1605`_).

*

Expand All @@ -15,6 +16,7 @@
`@marscher`. Thanks `@nicoddemus` for his help.

.. _#1580: https://github.com/pytest-dev/pytest/issues/1580
.. _#1605: https://github.com/pytest-dev/pytest/issues/1605

.. _@graingert: https://github.com/graingert

Expand Down
3 changes: 3 additions & 0 deletions _pytest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,10 @@ def _repr_failure_py(self, excinfo, style=None):
if self.config.option.fulltrace:
style="long"
else:
tb = _pytest._code.Traceback([excinfo.traceback[-1]])
self._prunetraceback(excinfo)
if len(excinfo.traceback) == 0:
excinfo.traceback = tb
tbfilter = False # prunetraceback already does it
if style == "auto":
style = "long"
Expand Down
33 changes: 33 additions & 0 deletions testing/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,39 @@ def teardown_function(func):
assert reps[5].nodeid.endswith("test_func")
assert reps[5].failed

def test_exact_teardown_issue1206(self, testdir):
rec = testdir.inline_runsource("""
import pytest

class TestClass:
def teardown_method(self):
pass

def test_method(self):
assert True
""")
reps = rec.getreports("pytest_runtest_logreport")
print (reps)
assert len(reps) == 3
#
assert reps[0].nodeid.endswith("test_method")
assert reps[0].passed
assert reps[0].when == 'setup'
#
assert reps[1].nodeid.endswith("test_method")
assert reps[1].passed
assert reps[1].when == 'call'
#
assert reps[2].nodeid.endswith("test_method")
assert reps[2].failed
assert reps[2].when == "teardown"
assert reps[2].longrepr.reprcrash.message in (
# python3 error
'TypeError: teardown_method() takes 1 positional argument but 2 were given',
# python2 error
'TypeError: teardown_method() takes exactly 1 argument (2 given)'
)

def test_failure_in_setup_function_ignores_custom_repr(self, testdir):
testdir.makepyfile(conftest="""
import pytest
Expand Down