Storing sys.last_traceback: test, docs and changelog

This commit is contained in:
Almar Klein 2015-03-21 17:06:24 +01:00
parent 9726fafa98
commit 0fc75c9622
3 changed files with 22 additions and 0 deletions

View File

@ -1,6 +1,10 @@
2.7.0.dev (compared to 2.6.4) 2.7.0.dev (compared to 2.6.4)
----------------------------- -----------------------------
- On failure, the ``sys.last_value``, ``sys.last_type`` and
``sys.last_traceback`` are set, so that a user can inspect the error
via postmortem debugging.
- fix issue616: conftest.py files and their contained fixutres are now - fix issue616: conftest.py files and their contained fixutres are now
properly considered for visibility, independently from the exact properly considered for visibility, independently from the exact
current working directory and test arguments that are used. current working directory and test arguments that are used.

View File

@ -87,6 +87,9 @@ failure situation::
py.test -x --pdb # drop to PDB on first failure, then end test session py.test -x --pdb # drop to PDB on first failure, then end test session
py.test --pdb --maxfail=3 # drop to PDB for first three failures py.test --pdb --maxfail=3 # drop to PDB for first three failures
Note that on any failure the exception information is stored on
``sys.last_traceback``. In interactive use, this allows one to drop
into postmortem debugging with any debug tool.
Setting a breakpoint / aka ``set_trace()`` Setting a breakpoint / aka ``set_trace()``
---------------------------------------------------- ----------------------------------------------------

View File

@ -525,3 +525,18 @@ def test_makereport_getsource(testdir):
result = testdir.runpytest() result = testdir.runpytest()
assert 'INTERNALERROR' not in result.stdout.str() assert 'INTERNALERROR' not in result.stdout.str()
result.stdout.fnmatch_lines(['*else: assert False*']) result.stdout.fnmatch_lines(['*else: assert False*'])
def test_store_except_info_on_eror(testdir):
# Simulate item that raises a specific exception
class ItemThatRaises:
def runtest(self):
raise IndexError('TEST')
try:
runner.pytest_runtest_call(ItemThatRaises())
except IndexError:
pass
# Check that exception info is stored on sys
assert sys.last_type is IndexError
assert sys.last_value.args[0] == 'TEST'
assert sys.last_traceback