diff --git a/CHANGELOG b/CHANGELOG index 9c19bd89d..64d48e193 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,9 @@ Changes between 2.0.2 and 2.0.3.dev ---------------------------------------------- +- fix issue38: nicer tracebacks on calls to hooks, particularly early + configure/sessionstart ones + - fix missing skip reason/meta information in junitxml files, reported via http://lists.idyll.org/pipermail/testing-in-python/2011-March/003928.html diff --git a/_pytest/core.py b/_pytest/core.py index abe7a26de..2087a8401 100644 --- a/_pytest/core.py +++ b/_pytest/core.py @@ -265,8 +265,15 @@ class PluginManager(object): config.hook.pytest_unconfigure(config=config) config.pluginmanager.unregister(self) - def notify_exception(self, excinfo): - excrepr = excinfo.getrepr(funcargs=True, showlocals=True) + def notify_exception(self, excinfo, option=None): + if option and option.fulltrace: + style = "long" + else: + style = "native" + excrepr = excinfo.getrepr(funcargs=True, + showlocals=getattr(option, 'showlocals', False), + style=style, + ) res = self.hook.pytest_internalerror(excrepr=excrepr) if not py.builtin.any(res): for line in str(excrepr).split("\n"): diff --git a/_pytest/main.py b/_pytest/main.py index d7948c6fa..f73ff597a 100644 --- a/_pytest/main.py +++ b/_pytest/main.py @@ -71,7 +71,7 @@ def pytest_cmdline_main(config): session.exitstatus = EXIT_INTERRUPTED except: excinfo = py.code.ExceptionInfo() - config.pluginmanager.notify_exception(excinfo) + config.pluginmanager.notify_exception(excinfo, config.option) session.exitstatus = EXIT_INTERNALERROR if excinfo.errisinstance(SystemExit): sys.stderr.write("mainloop: caught Spurious SystemExit!\n") diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index 7d00d056a..f67eb2847 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -13,6 +13,26 @@ class TestGeneralUsage: '*ERROR: hello' ]) + def test_early_hook_error_issue38_1(self, testdir): + testdir.makeconftest(""" + def pytest_sessionstart(): + 0 / 0 + """) + result = testdir.runpytest(testdir.tmpdir) + assert result.ret != 0 + # tracestyle is native by default for hook failures + result.stdout.fnmatch_lines([ + '*INTERNALERROR*File*conftest.py*line 2*', + '*0 / 0*', + ]) + result = testdir.runpytest(testdir.tmpdir, "--fulltrace") + assert result.ret != 0 + # tracestyle is native by default for hook failures + result.stdout.fnmatch_lines([ + '*INTERNALERROR*def pytest_sessionstart():*', + '*INTERNALERROR*0 / 0*', + ]) + def test_file_not_found(self, testdir): result = testdir.runpytest("asd") assert result.ret != 0