Skip to content

Prompt user for input during test run #5053

Closed
@rogerdahl

Description

@rogerdahl

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 :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: questiongeneral question, might be closed after 2 weeks of inactivity

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions