Skip to content

Commit 9662f82

Browse files
committed
re-use tmpfile for devnull
1 parent 05405bb commit 9662f82

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/_pytest/capture.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,14 @@ def __init__(self, targetfd, tmpfile=None, capman: Optional[CaptureManager] = No
573573
self.done = self._done
574574
if targetfd == 0:
575575
assert not tmpfile, "cannot set tmpfile with stdin"
576-
tmpfile = open(os.devnull, "r")
576+
if capman:
577+
try:
578+
tmpfile = capman._tmpfiles[0]
579+
assert not tmpfile.closed
580+
except KeyError:
581+
tmpfile = open(os.devnull, "r")
582+
else:
583+
tmpfile = open(os.devnull, "r")
577584
self.syscapture = SysCapture(targetfd)
578585
else:
579586
if tmpfile is None:

0 commit comments

Comments
 (0)