fix issue38 - nicer tracebacks on sessionstart/configure (and other internal/custom hook failures)
This commit is contained in:
parent
bc4e4b38a9
commit
06ca7090f9
|
@ -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
|
||||
|
||||
|
|
|
@ -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"):
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue