We are sucessfully using pytest (Python 3) to run a test suite testing some hardware devices (electronics). For a subset of these tests, we need the tester to change the hardwa
So, I found a hint by a pytest dev, based on which I basically do what the capsys.disable()
function does:
@pytest.fixture(scope="module")
def disconnect_component(pytestconfig):
capmanager = pytestconfig.pluginmanager.getplugin('capturemanager')
capmanager.suspend_global_capture(in_=True)
input('Disconnect component, then press enter')
capmanager.resume_global_capture()
yield # At this point all the tests with this fixture are run
capmanager.suspend_global_capture(in_=True)
input('Connect component again, then press enter')
capmanager.resume_global_capture()
This works flawlessly as far as I can see. Don't forget the in_=True
bit.
Edit: From pytest 3.3.0 (I think), capmanager.suspendcapture
and capmanager.resumecapture
were renamed to capmanager.suspend_global_capture
and capmanager.resume_global_capture
, respectively.