From 539f828cdd672d288949f46dd81008e79f90f434 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Wed, 24 Nov 2010 16:43:55 +0100 Subject: [PATCH] also accept non-pytrace pytest.fail() call in setup/teardown methods --- _pytest/python.py | 6 +++--- testing/test_runner.py | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/_pytest/python.py b/_pytest/python.py index 3c4374f43..c894becb6 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -324,14 +324,14 @@ class FunctionMixin(PyobjMixin): if line.strip().startswith('def'): return FuncargLookupErrorRepr(fspath, lineno, lines[:i+1], str(excinfo.value)) + if excinfo.errisinstance(pytest.fail.Exception): + if not excinfo.value.pytrace: + return str(excinfo.value) return super(FunctionMixin, self)._repr_failure_py(excinfo, style=style) def repr_failure(self, excinfo, outerr=None): assert outerr is None, "XXX outerr usage is deprecated" - if excinfo.errisinstance(pytest.fail.Exception): - if not excinfo.value.pytrace: - return str(excinfo.value) return self._repr_failure_py(excinfo, style=self.config.option.tbstyle) diff --git a/testing/test_runner.py b/testing/test_runner.py index 379476d40..6ec9a66f1 100644 --- a/testing/test_runner.py +++ b/testing/test_runner.py @@ -339,11 +339,15 @@ def test_pytest_fail_notrace(testdir): import pytest def test_hello(): pytest.fail("hello", pytrace=False) + def teardown_function(function): + pytest.fail("world", pytrace=False) """) result = testdir.runpytest() result.stdout.fnmatch_lines([ - "hello" + "world", + "hello", ]) + assert 'def teardown_function' not in result.stdout.str() def test_exception_printing_skip(): try: