summaryrefslogtreecommitdiff
path: root/src/_pytest/debugging.py
diff options
context:
space:
mode:
authorBruno Oliveira <nicoddemus@gmail.com>2020-05-01 17:21:15 -0300
committerBruno Oliveira <nicoddemus@gmail.com>2020-05-02 15:26:55 -0300
commit5c2e96c0e65bea2b733a5ccd94507d95e8cba12b (patch)
treebb3fae42c836f6ed1c5768daf96de1e6f3900049 /src/_pytest/debugging.py
parent2b51ed46d54be58da6bbcd28f68149b3fc2cd104 (diff)
downloadpytest-5c2e96c0e65bea2b733a5ccd94507d95e8cba12b.tar.gz
Fix cleanup functions not being invoked on test failures
Also delay calling tearDown() when --pdb is given, so users still have access to the instance variables (which are usually cleaned up during tearDown()) when debugging. Fix #6947
Diffstat (limited to 'src/_pytest/debugging.py')
-rw-r--r--src/_pytest/debugging.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/_pytest/debugging.py b/src/_pytest/debugging.py
index 9155d7e98..17915db73 100644
--- a/src/_pytest/debugging.py
+++ b/src/_pytest/debugging.py
@@ -272,11 +272,15 @@ class PdbInvoke:
class PdbTrace:
@hookimpl(hookwrapper=True)
def pytest_pyfunc_call(self, pyfuncitem):
- _test_pytest_function(pyfuncitem)
+ wrap_pytest_function_for_tracing(pyfuncitem)
yield
-def _test_pytest_function(pyfuncitem):
+def wrap_pytest_function_for_tracing(pyfuncitem):
+ """Changes the python function object of the given Function item by a wrapper which actually
+ enters pdb before calling the python function itself, effectively leaving the user
+ in the pdb prompt in the first statement of the function.
+ """
_pdb = pytestPDB._init_pdb("runcall")
testfunction = pyfuncitem.obj
@@ -291,6 +295,13 @@ def _test_pytest_function(pyfuncitem):
pyfuncitem.obj = wrapper
+def maybe_wrap_pytest_function_for_tracing(pyfuncitem):
+ """Wrap the given pytestfunct item for tracing support if --trace was given in
+ the command line"""
+ if pyfuncitem.config.getvalue("trace"):
+ wrap_pytest_function_for_tracing(pyfuncitem)
+
+
def _enter_pdb(node, excinfo, rep):
# XXX we re-use the TerminalReporter's terminalwriter
# because this seems to avoid some encoding related troubles