Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions pytest_pudb.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pudb
import sys
import warnings
import _pytest.unittest


def pytest_addoption(parser):
Expand All @@ -13,10 +14,6 @@ def pytest_addoption(parser):

def pytest_configure(config):
pudb_wrapper = PuDBWrapper(config)

if config.getvalue("usepudb"):
config.pluginmanager.register(pudb_wrapper, 'pudb_wrapper')

pudb_wrapper.mount()
config._cleanup.append(pudb_wrapper.unmount)

Expand All @@ -30,16 +27,38 @@ def __init__(self, config):
self.config = config
self.pluginmanager = config.pluginmanager
self._pudb_get_debugger = None
self._test_case_function_runtest = None

@property
def with_pudb_option(self):
return self.config.getvalue("usepudb")

def mount(self):
self._pudb_get_debugger = pudb._get_debugger
pudb._get_debugger = self._get_debugger

if self.with_pudb_option:
self.config.pluginmanager.register(self, 'pudb_wrapper')

def runtest(self):
# disables tearDown and cleanups for post mortem debugging
# see: https://github.com/pytest-dev/pytest/pull/1890
if self._handle_skip():
return
self._testcase.debug()

self._test_case_function_runtest = _pytest.unittest.TestCaseFunction.runtest
_pytest.unittest.TestCaseFunction.runtest = runtest

def unmount(self):
if self._pudb_get_debugger:
pudb._get_debugger = self._pudb_get_debugger
self._pudb_get_debugger = None

if self._test_case_function_runtest:
_pytest.unittest.TestCaseFunction.runtest = self._test_case_function_runtest
self._test_case_function_runtest = None

def disable_io_capture(self):
if self.pluginmanager is not None:
capman = self.pluginmanager.getplugin("capturemanager")
Expand Down
22 changes: 22 additions & 0 deletions test_pytest_pudb.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,28 @@ def test_1():
child.sendeof()


def test_pudb_unittest_teardown_interaction(testdir):
p1 = testdir.makepyfile("""
import unittest
class Blub(unittest.TestCase):
def tearDown(self):
self.a = False
def test_false(self):
self.a = True
self.fail()
""")
child = testdir.spawn_pytest("--pudb %s" % p1)
child.expect("PuDB")
child.expect(HELP_MESSAGE)
child.expect("PROCESSING EXCEPTION")
child.expect(VARIABLES_TABLE)
child.send('V') # Move to variables
child.send('n') # Add watch expression
child.expect('Add Watch Expression')
child.sendline('self.a') # Set self.a
child.expect('self.a: \x1b\\[0;30;42mTrue')
child.sendeof()

def test_pudb_set_trace_integration(testdir):
p1 = testdir.makepyfile("""
def test_1():
Expand Down