How to make pytest wait for (manual) user action?

前端 未结 5 1787
抹茶落季
抹茶落季 2021-02-13 15:36

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

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-13 16:21

    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.

提交回复
热议问题