Skip to content

Commit 017e504

Browse files
authored
Merge pull request #4277 from blueyed/pdb-set_trace-capture-msg
pdb: improve msg about output capturing with set_trace
2 parents 233c2a2 + 65817dd commit 017e504

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

changelog/4277.trivial.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
pdb: improve message about output capturing with ``set_trace``.
2+
3+
Do not display "IO-capturing turned off/on" when ``-s`` is used to avoid
4+
confusion.

src/_pytest/capture.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ def _getcapture(self, method):
102102

103103
# Global capturing control
104104

105+
def is_globally_capturing(self):
106+
return self._method != "no"
107+
105108
def start_global_capturing(self):
106109
assert self._global_capturing is None
107110
self._global_capturing = self._getcapture(self._method)

src/_pytest/debugging.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ def set_trace(cls, set_break=True):
8080
capman.suspend_global_capture(in_=True)
8181
tw = _pytest.config.create_terminal_writer(cls._config)
8282
tw.line()
83-
tw.sep(">", "PDB set_trace (IO-capturing turned off)")
83+
if capman and capman.is_globally_capturing():
84+
tw.sep(">", "PDB set_trace (IO-capturing turned off)")
85+
else:
86+
tw.sep(">", "PDB set_trace")
8487

8588
class _PdbWrapper(cls._pdb_cls, object):
8689
_pytest_capman = capman
@@ -91,7 +94,10 @@ def do_continue(self, arg):
9194
if self._pytest_capman:
9295
tw = _pytest.config.create_terminal_writer(cls._config)
9396
tw.line()
94-
tw.sep(">", "PDB continue (IO-capturing resumed)")
97+
if self._pytest_capman.is_globally_capturing():
98+
tw.sep(">", "PDB continue (IO-capturing resumed)")
99+
else:
100+
tw.sep(">", "PDB continue")
95101
self._pytest_capman.resume_global_capture()
96102
cls._pluginmanager.hook.pytest_leave_pdb(
97103
config=cls._config, pdb=self

testing/test_pdb.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,22 @@ def test_1():
518518
assert "1 failed" in rest
519519
self.flush(child)
520520

521+
def test_pdb_without_capture(self, testdir):
522+
p1 = testdir.makepyfile(
523+
"""
524+
import pytest
525+
def test_1():
526+
pytest.set_trace()
527+
"""
528+
)
529+
child = testdir.spawn_pytest("-s %s" % p1)
530+
child.expect(r">>> PDB set_trace >>>")
531+
child.expect("Pdb")
532+
child.sendline("c")
533+
child.expect(r">>> PDB continue >>>")
534+
child.expect("1 passed")
535+
self.flush(child)
536+
521537
def test_pdb_used_outside_test(self, testdir):
522538
p1 = testdir.makepyfile(
523539
"""

0 commit comments

Comments
 (0)