Prompt user for input during test run
See original GitHub issueFrom the docs:
In addition, stdin is set to a “null” object which will fail on attempts to read from it because it is rarely desired to wait for interactive input when running automated tests.
Well, I find myself really desiring the rarely desired ability to wait for interactive input during test runs. I have a pytest based test system that I think is rather nifty, that automatically serializes test output from new tests to files. During regular pytest runs, the test output is compared to the files and tests fail on mismatches. However, I have a mode I can enable with a pytest switch that doesn’t immediately fail tests on mismatches. Instead, it pops up a diff and (here’s the issue), asks the user if the test should be failed, or if it should just update the reference file to match and keep going.
For my use case, this setup has saved me from writing lots of asserts and made for better tests at the same time. But for now, it only works with --capture=no. I’m aware of the capture fixtures that allow temporarily disabling capturing. Those would probably work for this, but I have maybe 1000 tests that use this sample file based system and I’m looking for a less invasive way. I don’t want to add a capture fixture argument to each of the test function, and then having to pass it along into the helper functions that eventually issue the user input prompt.
I think the ideal solution would be to have a context manager that I could import directly from the pytest module and wrap the user input function with. Is anything like that available? If not, any tips on how to get this working would be much appreciated 😃
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (3 by maintainers)
Top Related StackOverflow Question
Did some tests, and my use case is resolved by using
--capture=sysand a custominput()function that uses the file descriptors:@b0g3r I realized that I didn’t need an input prompt. When there is a mismatch, I open a diff tool (I’m currently using
meld), showing current result on one side and expected result on the other. If I want to update the expected result, I just do aMerge all from leftinmeld). I use a global lock on openingmeldso that only one instance is opened at a time. Works nicely also when running the tests in parallel withxdist.