We successfully use pytest (Python 3) to run a test suite that tests some hardware devices (electronics). For a subset of these tests, we need a tester to change the hardware device and then change it. My approach was to use a modular device attached to the tests in question (they are all in a separate module), with two calls input:
@pytest.fixture(scope="module")
def disconnect_component():
input('Disconnect component, then press enter')
yield
input('Connect component again, then press enter')
When doing this, I get OSError: reading from stdin while output is captured. I can avoid this by calling pytest with --capture=no, and confirmed that my approach works, that is, I get the first request before the subset in question, and the second after launch.
The big drawback is that it deactivates the stdin / stderr capture for the entire test suite that some other tests rely on.
I also tried using capsys.disabled( docs ) like this
@pytest.fixture(scope="module")
def disconnect_component(capsys):
with capsys.disabled():
input('Disconnect component, then press enter')
yield
input('Connect component again, then press enter')
but at startup I get ScopeMismatch: You tried to access the 'function' scoped fixture 'capsys' with a 'module' scoped request object, involved factories.
Can I make pytest wait for user action in some other way than input? If not, can I disable capture only for tests using the above device?
source
share