capture ¤
Enumeration of possible output captures.
Capture ¤
Bases: Enum
An enum to store the different possible output types.
cast classmethod
¤
Cast a value to an actual Capture enumeration value.
Parameters:
Returns:
-
Capture
–A Capture enumeration value.
Source code in src/failprint/capture.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
|
here ¤
here(stdin: str | None = None) -> Iterator[CaptureManager]
Context manager to capture standard output/error.
Parameters:
-
stdin
(str | None
, default:None
) –Optional input.
Yields:
-
CaptureManager
–A lazy string with the captured contents.
Examples:
>>> def print_things() -> None:
... print("1")
... sys.stderr.write("2\n")
... os.system("echo 3")
... subprocess.run(["sh", "-c", "echo 4 >&2"])
>>> with Capture.BOTH.here() as captured:
... print_things()
... print(captured)
1
2
3
4
Source code in src/failprint/capture.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
|
CaptureManager ¤
Context manager to capture standard output and error at the file descriptor level.
Usable directly through Capture.here
.
Examples:
>>> def print_things() -> None:
... print("1")
... sys.stderr.write("2\n")
... os.system("echo 3")
... subprocess.run(["sh", "-c", "echo 4 >&2"])
>>> with CaptureManager(Capture.BOTH) as captured:
... print_things()
... print(captured)
1
2
3
4
Parameters:
-
capture
(Capture
, default:BOTH
) –What to capture.
-
stdin
(str | None
, default:None
) –Optional input.
Source code in src/failprint/capture.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
|
output property
¤
output: str
Captured output.
Raises:
-
RuntimeError
–When accessing captured output before exiting the context manager.