Skip to content

[WIP] pytester: parseconfig: use -p no:capture with suspended capture #5967

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

Closed
Closed
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 src/_pytest/pytester.py
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,10 @@ def parseconfig(self, *args):

import _pytest.config

capman = self.request.config.pluginmanager.getplugin("capturemanager")
if capman and not capman.is_capturing():
args = ["-p", "no:capture"] + args

config = _pytest.config._prepareconfig(args, self.plugins)
# we don't know what the test will do with this half-setup config
# object and thus we make sure it gets unconfigured properly in any
Expand Down
19 changes: 19 additions & 0 deletions testing/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1217,3 +1217,22 @@ def set_trace(self, *args):
result.stdout.fnmatch_lines(
["*set_trace_called*", "*set_trace_called*", "* 1 passed in *"]
)


def test_capture_with_testdir_parseconfig(testdir):
"""Test capturing with inner node of config setup. Also tests #4330."""
p = testdir.makepyfile(
"""
def test_inner(testdir):
hello = testdir.makefile(".py", hello="world")
__import__('pdb').set_trace()
node = testdir.parseconfig(hello)
"""
)
child = testdir.spawn_pytest("-s -p pytester %s" % p)
child.expect(r"\(Pdb")
child.sendline("n")
child.sendline("c")
rest = child.read().decode("utf8")
TestPDB.flush(child)
assert child.exitstatus == 0, rest