Repository navigation
capsys input disable #13746
Replies: 1 comment
|
For a dedicated interactive maintenance run, a public-API workaround is to add pytest -s path/to/test_images.pyKeep your existing opt-in interactive flag too, if you have one. The distinction is that def test_prompt(capsys):
print("captured before")
assert capsys.readouterr().out == "captured before\n"
with capsys.disabled():
answer = input("Accept diff? [y/N] ")
assert answer.lower() == "y"
print("captured after")
assert capsys.readouterr().out == "captured after\n"I checked this with pytest 8.4.1 and 9.1.1: without This avoids reaching into Both the failing and working invocations were checked locally. |
Uh oh!
There was an error while loading. Please reload this page.
I have a baseline image diff test, for which I define an interactive mode, allowing diffs to be accepted or declined one by one. This works with X11 for the diff frontend and I block on the validation assert until input accepts or not (when in interactive mode).
I want to do a terminal version of this, but
capsys.disable()doesn't pass through theinflag tosuspend_captureherepytest/src/_pytest/capture.py
Line 668 in 958981c
The intervening call to
suspend_global_captureon multicapture herepytest/src/_pytest/capture.py
Line 788 in 958981c
does deal with input.
I think it would be as easy as modifying
CaptureFixtureto pass the boolean for input herepytest/src/_pytest/capture.py
Line 987 in 958981c
and wire it through here
pytest/src/_pytest/capture.py
Line 841 in 958981c
with sensible current-behavior defaults.
I appreciate reading from
stdinisn't a great idea for automated tests - this is intended for interactive maintenance of baseline image diffs only.Meanwhile I can do the utterly horrible
Any thoughts?
All reactions