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

前端 未结 5 1786
抹茶落季
抹茶落季 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:29

    As of pytest 5, as a fixture, you can use this:

    @pytest.fixture
    def suspend_capture(pytestconfig):
        class suspend_guard:
            def __init__(self):
                self.capmanager = pytestconfig.pluginmanager.getplugin('capturemanager')
            def __enter__(self):
                self.capmanager.suspend_global_capture(in_=True)
            def __exit__(self, _1, _2, _3):
                self.capmanager.resume_global_capture()
    
        yield suspend_guard()
    

    Example usage:

    def test_input(suspend_capture):
        with suspend_capture:
            input("hello")
    

提交回复
热议问题