diff --git a/CHANGELOG b/CHANGELOG index 530ecf0ea..089350d8a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -7,6 +7,9 @@ `Config.fromdictargs` now represents its input much more faithfully. Thanks to Buck Evan for the complete PR. +* `pytest_enter_pdb` now optionally receives the pytest config object. + Thanks Bruno Oliveira for the PR. + 2.8.2.dev --------- diff --git a/_pytest/hookspec.py b/_pytest/hookspec.py index d0c3e4aad..a9024b1d3 100644 --- a/_pytest/hookspec.py +++ b/_pytest/hookspec.py @@ -290,5 +290,10 @@ def pytest_exception_interact(node, call, report): that is not an internal exception like "skip.Exception". """ -def pytest_enter_pdb(): - """ called upon pdb.set_trace()""" +def pytest_enter_pdb(config): + """ called upon pdb.set_trace(), can be used by plugins to take special + action just before the python debugger enters in interactive mode. + + :arg config: pytest config object + :type config: _pytest.config.Config + """ diff --git a/_pytest/pdb.py b/_pytest/pdb.py index 78fedd373..8a615d0d3 100644 --- a/_pytest/pdb.py +++ b/_pytest/pdb.py @@ -37,7 +37,6 @@ class pytestPDB: """ invoke PDB set_trace debugging, dropping any IO capturing. """ import _pytest.config frame = sys._getframe().f_back - capman = None if self._pluginmanager is not None: capman = self._pluginmanager.getplugin("capturemanager") if capman: @@ -45,7 +44,7 @@ class pytestPDB: tw = _pytest.config.create_terminal_writer(self._config) tw.line() tw.sep(">", "PDB set_trace (IO-capturing turned off)") - self._pluginmanager.hook.pytest_enter_pdb() + self._pluginmanager.hook.pytest_enter_pdb(config=self._config) pdb.Pdb().set_trace(frame) diff --git a/doc/en/writing_plugins.rst b/doc/en/writing_plugins.rst index 1e9807cf5..f5e4ce66c 100644 --- a/doc/en/writing_plugins.rst +++ b/doc/en/writing_plugins.rst @@ -501,7 +501,7 @@ reporting or interaction with exceptions: .. autofunction:: pytest_internalerror .. autofunction:: pytest_keyboard_interrupt .. autofunction:: pytest_exception_interact - +.. autofunction:: pytest_enter_pdb Reference of objects involved in hooks diff --git a/testing/test_pdb.py b/testing/test_pdb.py index a2fd4d43d..06fc056e3 100644 --- a/testing/test_pdb.py +++ b/testing/test_pdb.py @@ -275,8 +275,12 @@ class TestPDB: def test_enter_pdb_hook_is_called(self, testdir): testdir.makeconftest(""" - def pytest_enter_pdb(): + def pytest_enter_pdb(config): + assert config.testing_verification == 'configured' print 'enter_pdb_hook' + + def pytest_configure(config): + config.testing_verification = 'configured' """) p1 = testdir.makepyfile(""" import pytest