diff --git a/src/_pytest/pytester.py b/src/_pytest/pytester.py index a050dad09e5..1d8ae798820 100644 --- a/src/_pytest/pytester.py +++ b/src/_pytest/pytester.py @@ -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 diff --git a/testing/test_pdb.py b/testing/test_pdb.py index 3c56f40e1cb..b8af4198ae0 100644 --- a/testing/test_pdb.py +++ b/testing/test_pdb.py @@ -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