From 1f148a93ecb7c8aa4d33335f9251d083551a33bb Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Mon, 23 Nov 2015 12:59:56 -0200 Subject: [PATCH 1/2] Mention pytest_enter_pdb in the docs --- _pytest/hookspec.py | 4 +++- doc/en/writing_plugins.rst | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/_pytest/hookspec.py b/_pytest/hookspec.py index d0c3e4aad..113915d2d 100644 --- a/_pytest/hookspec.py +++ b/_pytest/hookspec.py @@ -291,4 +291,6 @@ def pytest_exception_interact(node, call, report): """ def pytest_enter_pdb(): - """ called upon pdb.set_trace()""" + """ called upon pdb.set_trace(), can be used by plugins to take special + action just before the python debugger enters in interactive mode. + """ 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 From b3166a538c3b35c6dbde9b52f9d48278fc7dcfed Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Mon, 23 Nov 2015 13:05:56 -0200 Subject: [PATCH 2/2] Pass pytest's config object to pytest_enter_pdb --- CHANGELOG | 3 +++ _pytest/hookspec.py | 5 ++++- _pytest/pdb.py | 3 +-- testing/test_pdb.py | 6 +++++- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index e20532a9b..91c006553 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,6 +4,9 @@ * New `pytest.mark.skip` mark, which unconditional skips marked tests. Thanks Michael Aquilina 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 113915d2d..a9024b1d3 100644 --- a/_pytest/hookspec.py +++ b/_pytest/hookspec.py @@ -290,7 +290,10 @@ def pytest_exception_interact(node, call, report): that is not an internal exception like "skip.Exception". """ -def pytest_enter_pdb(): +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/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