fix issue38 - nicer tracebacks on sessionstart/configure (and other internal/custom hook failures)

This commit is contained in:
holger krekel 2011-04-17 12:20:11 +02:00
parent bc4e4b38a9
commit 06ca7090f9
4 changed files with 33 additions and 3 deletions

View File

@ -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

View File

@ -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"):

View File

@ -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")

View File

@ -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