From e0038b82f7e76b73f2555fc8b065f94513570020 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 31 Oct 2018 16:59:07 +0100 Subject: [PATCH 1/2] pdb: improve msg about output capturing with set_trace Do not display "IO-capturing turned off/on" when ``-s`` is used to avoid confusion. --- src/_pytest/capture.py | 3 +++ src/_pytest/debugging.py | 10 ++++++++-- testing/test_pdb.py | 16 ++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/_pytest/capture.py b/src/_pytest/capture.py index bc50ccc3f08..e4187ee295b 100644 --- a/src/_pytest/capture.py +++ b/src/_pytest/capture.py @@ -102,6 +102,9 @@ def _getcapture(self, method): # Global capturing control + def is_globally_capturing(self): + return self._method != "no" + def start_global_capturing(self): assert self._global_capturing is None self._global_capturing = self._getcapture(self._method) diff --git a/src/_pytest/debugging.py b/src/_pytest/debugging.py index 1ae221aa058..94866de5633 100644 --- a/src/_pytest/debugging.py +++ b/src/_pytest/debugging.py @@ -80,7 +80,10 @@ def set_trace(cls, set_break=True): capman.suspend_global_capture(in_=True) tw = _pytest.config.create_terminal_writer(cls._config) tw.line() - tw.sep(">", "PDB set_trace (IO-capturing turned off)") + if capman and capman.is_globally_capturing(): + tw.sep(">", "PDB set_trace (IO-capturing turned off)") + else: + tw.sep(">", "PDB set_trace") class _PdbWrapper(cls._pdb_cls, object): _pytest_capman = capman @@ -91,7 +94,10 @@ def do_continue(self, arg): if self._pytest_capman: tw = _pytest.config.create_terminal_writer(cls._config) tw.line() - tw.sep(">", "PDB continue (IO-capturing resumed)") + if self._pytest_capman.is_globally_capturing(): + tw.sep(">", "PDB continue (IO-capturing resumed)") + else: + tw.sep(">", "PDB continue") self._pytest_capman.resume_global_capture() cls._pluginmanager.hook.pytest_leave_pdb( config=cls._config, pdb=self diff --git a/testing/test_pdb.py b/testing/test_pdb.py index 98185ab17d4..4c236c55d52 100644 --- a/testing/test_pdb.py +++ b/testing/test_pdb.py @@ -518,6 +518,22 @@ def test_1(): assert "1 failed" in rest self.flush(child) + def test_pdb_without_capture(self, testdir): + p1 = testdir.makepyfile( + """ + import pytest + def test_1(): + pytest.set_trace() + """ + ) + child = testdir.spawn_pytest("-s %s" % p1) + child.expect(r">>> PDB set_trace >>>") + child.expect("Pdb") + child.sendline("c") + child.expect(r">>> PDB continue >>>") + child.expect("1 passed") + self.flush(child) + def test_pdb_used_outside_test(self, testdir): p1 = testdir.makepyfile( """ From 65817dd7975610d459467c4911b45f6bffe5352d Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 31 Oct 2018 23:08:59 +0100 Subject: [PATCH 2/2] changelog [ci skip] --- changelog/4277.trivial.rst | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 changelog/4277.trivial.rst diff --git a/changelog/4277.trivial.rst b/changelog/4277.trivial.rst new file mode 100644 index 00000000000..69118788202 --- /dev/null +++ b/changelog/4277.trivial.rst @@ -0,0 +1,4 @@ +pdb: improve message about output capturing with ``set_trace``. + +Do not display "IO-capturing turned off/on" when ``-s`` is used to avoid +confusion.