4 new commits in pytest:
https://bitbucket.org/pytest-dev/pytest/commits/1cce2942bd98/
Changeset: 1cce2942bd98
User: almarklein
Date: 2015-03-21 08:26:35+00:00
Summary: allow postmortem debugging on failed test
Affected #: 1 file
diff -r 39361b33346e784e4f6359dbdba9c9957a8e4cd7 -r
1cce2942bd98d84589bb8b7dc1cb6e45af7e8966 _pytest/runner.py
--- a/_pytest/runner.py
+++ b/_pytest/runner.py
@@ -86,7 +86,17 @@
item.session._setupstate.prepare(item)
def pytest_runtest_call(item):
- item.runtest()
+ try:
+ item.runtest()
+ except Exception:
+ # Store trace info to allow postmortem debugging
+ type, value, tb = sys.exc_info()
+ tb = tb.tb_next # Skip *this* frame
+ sys.last_type = type
+ sys.last_value = value
+ sys.last_traceback = tb
+ del tb # Get rid of it in this namespace
+ raise
def pytest_runtest_teardown(item, nextitem):
item.session._setupstate.teardown_exact(item, nextitem)
https://bitbucket.org/pytest-dev/pytest/commits/9a5a37b91dd9/
Changeset: 9a5a37b91dd9
User: almarklein
Date: 2015-03-21 16:06:24+00:00
Summary: Storing sys.last_traceback: test, docs and changelog
Affected #: 3 files
diff -r 1cce2942bd98d84589bb8b7dc1cb6e45af7e8966 -r
9a5a37b91dd9cec5fa4d988bd290d8ade3ebb544 CHANGELOG
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,10 @@
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
properly considered for visibility, independently from the exact
current working directory and test arguments that are used.
diff -r 1cce2942bd98d84589bb8b7dc1cb6e45af7e8966 -r
9a5a37b91dd9cec5fa4d988bd290d8ade3ebb544 doc/en/usage.txt
--- a/doc/en/usage.txt
+++ b/doc/en/usage.txt
@@ -87,6 +87,9 @@
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
+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()``
----------------------------------------------------
diff -r 1cce2942bd98d84589bb8b7dc1cb6e45af7e8966 -r
9a5a37b91dd9cec5fa4d988bd290d8ade3ebb544 testing/test_runner.py
--- a/testing/test_runner.py
+++ b/testing/test_runner.py
@@ -525,3 +525,18 @@
result = testdir.runpytest()
assert 'INTERNALERROR' not in result.stdout.str()
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
https://bitbucket.org/pytest-dev/pytest/commits/459c55d80c6b/
Changeset: 459c55d80c6b
User: almarklein
Date: 2015-03-21 16:26:23+00:00
Summary: address reviewer comments
Affected #: 2 files
diff -r 9a5a37b91dd9cec5fa4d988bd290d8ade3ebb544 -r
459c55d80c6bc1a9d70699e9d129c7d23597a0a4 doc/en/usage.txt
--- a/doc/en/usage.txt
+++ b/doc/en/usage.txt
@@ -88,8 +88,16 @@
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.
+``sys.last_value``, ``sys.last_type`` and ``sys.last_traceback``. In
+interactive use, this allows one to drop into postmortem debugging with
+any debug tool. One can also manually access the exception information,
+for example::
+
+ >> import sys
+ >> sys.last_traceback.tb_lineno
+ 42
+ >> sys.last_value
+ AssertionError('assert result == "ok"',)
Setting a breakpoint / aka ``set_trace()``
----------------------------------------------------
diff -r 9a5a37b91dd9cec5fa4d988bd290d8ade3ebb544 -r
459c55d80c6bc1a9d70699e9d129c7d23597a0a4 testing/test_runner.py
--- a/testing/test_runner.py
+++ b/testing/test_runner.py
@@ -527,7 +527,10 @@
result.stdout.fnmatch_lines(['*else: assert False*'])
-def test_store_except_info_on_eror(testdir):
+def test_store_except_info_on_eror():
+ """ Test that upon test failure, the exception info is stored on
+ sys.last_traceback and friends.
+ """
# Simulate item that raises a specific exception
class ItemThatRaises:
def runtest(self):
https://bitbucket.org/pytest-dev/pytest/commits/08307971b2c2/
Changeset: 08307971b2c2
User: bubenkoff
Date: 2015-03-23 20:25:10+00:00
Summary: merge almarklein/default
Affected #: 4 files
diff -r 8a9039aed7226910656320aec0ef51a27bc93caa -r
08307971b2c21e62f9f72f92db7f6644bf7baa42 CHANGELOG
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -62,6 +62,10 @@
- fix issue463: raise specific error for 'parameterize' misspelling
(pfctdayelise).
+- 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 (almarklein).
+
2.6.4
----------
diff -r 8a9039aed7226910656320aec0ef51a27bc93caa -r
08307971b2c21e62f9f72f92db7f6644bf7baa42 _pytest/runner.py
--- a/_pytest/runner.py
+++ b/_pytest/runner.py
@@ -86,7 +86,17 @@
item.session._setupstate.prepare(item)
def pytest_runtest_call(item):
- item.runtest()
+ try:
+ item.runtest()
+ except Exception:
+ # Store trace info to allow postmortem debugging
+ type, value, tb = sys.exc_info()
+ tb = tb.tb_next # Skip *this* frame
+ sys.last_type = type
+ sys.last_value = value
+ sys.last_traceback = tb
+ del tb # Get rid of it in this namespace
+ raise
def pytest_runtest_teardown(item, nextitem):
item.session._setupstate.teardown_exact(item, nextitem)
diff -r 8a9039aed7226910656320aec0ef51a27bc93caa -r
08307971b2c21e62f9f72f92db7f6644bf7baa42 doc/en/usage.txt
--- a/doc/en/usage.txt
+++ b/doc/en/usage.txt
@@ -87,6 +87,17 @@
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
+Note that on any failure the exception information is stored on
+``sys.last_value``, ``sys.last_type`` and ``sys.last_traceback``. In
+interactive use, this allows one to drop into postmortem debugging with
+any debug tool. One can also manually access the exception information,
+for example::
+
+ >> import sys
+ >> sys.last_traceback.tb_lineno
+ 42
+ >> sys.last_value
+ AssertionError('assert result == "ok"',)
Setting a breakpoint / aka ``set_trace()``
----------------------------------------------------
diff -r 8a9039aed7226910656320aec0ef51a27bc93caa -r
08307971b2c21e62f9f72f92db7f6644bf7baa42 testing/test_runner.py
--- a/testing/test_runner.py
+++ b/testing/test_runner.py
@@ -525,3 +525,21 @@
result = testdir.runpytest()
assert 'INTERNALERROR' not in result.stdout.str()
result.stdout.fnmatch_lines(['*else: assert False*'])
+
+
+def test_store_except_info_on_eror():
+ """ Test that upon test failure, the exception info is stored on
+ sys.last_traceback and friends.
+ """
+ # 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
Repository URL: https://bitbucket.org/pytest-dev/pytest/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
_______________________________________________
pytest-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pytest-commit