Prompt user for input during test run

See original GitHub issue

From 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:closed
  • Created 4 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
rogerdahlcommented, Apr 19, 2019

Did some tests, and my use case is resolved by using --capture=sys and a custom input() function that uses the file descriptors:

def fd_input(prompt):
    with os.fdopen(os.dup(1), "w") as stdout:
        stdout.write("\n{}? ".format(prompt))

    with os.fdopen(os.dup(2), "r") as stdin:
        return stdin.readline()
1reaction
rogerdahlcommented, Oct 18, 2020

@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 a Merge all from left in meld). I use a global lock on opening meld so that only one instance is opened at a time. Works nicely also when running the tests in parallel with xdist.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Making pytest wait for user input - python - Stack Overflow
When i run the command pytest name_of_test_file.py it runs fine, and stops after each test to get user input. However, i want to...
Read more >
How to prompt user for input at runtime - coded UI automated ...
I'd like to have a prompt come up during the test where the user can enter in the access code before the automated...
Read more >
User Input From a Prompt in JavaScript: A Quick Guide
The prompt() function shows a dialog box where the user is prompted to provide their information. If the user selects "OK," the prompt() ......
Read more >
Prompt User for Input Express VI - NI - National Instruments
Specifies the name and data type of the controls that appear in the dialog box. The Inputs you list here are returned as...
Read more >
Prompting User Input during automation - Katalon Studio
web-testing, katalon-studio · philin_philip February 8, 2018, 1:23am #1. Hi, I am new to Katalon. Is there a way to prompt user for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found