Skip to content

pdb: improve msg about output capturing with set_trace #4277

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 1, 2018
Merged
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
4 changes: 4 additions & 0 deletions changelog/4277.trivial.rst
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions src/_pytest/capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ def _getcapture(self, method):

# Global capturing control

def is_globally_capturing(self):
return self._method != "no"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've thought about having a is_suspended property instead also.
What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be self._method != "no" and not self._suspended, which is set internally then - or just self.suspended, which never gets set for method "no".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine actually.

def start_global_capturing(self):
assert self._global_capturing is None
self._global_capturing = self._getcapture(self._method)
Expand Down
10 changes: 8 additions & 2 deletions src/_pytest/debugging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
16 changes: 16 additions & 0 deletions testing/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
"""
Expand Down