-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Perform FD capturing even if the FD is invalid
The `FDCapture`/`FDCaptureBinary` classes, used by `capfd`/`capfdbinary` fixtures and the `--capture=fd` option (set by default), redirect FDs 1/2 (stdout/stderr) to a temporary file. To do this, they need to save the old file by duplicating the FD before redirecting it, to be restored once finished. Previously, if this duplicating (`os.dup()`) failed, most likely due to that FD being invalid, the FD redirection would silently not be done. The FD capturing also performs python-level redirection (monkeypatching `sys.stdout`/`sys.stderr`) which would still be done, but direct writes to the FDs would fail. This is not great. If pytest is run with `--capture=fd`, or a test is using `capfd`, it expects writes to the FD to work and be captured, regardless of external circumstances. So, instead of disabling FD capturing, keep the redirection to a temporary file, just don't restore it after closing, because there is nothing to restore to.
- Loading branch information
Showing
3 changed files
with
95 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
When ``fd`` capturing is used, through ``--capture=fd`` or the ``capfd`` and | ||
``capfdbinary`` fixtures, and the file descriptor (0, 1, 2) cannot be | ||
duplicated, FD capturing is still performed. Previously, direct writes to the | ||
file descriptors would fail or be lost in this case. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters