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

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

    Maybe it's worth noting that above solution doesn't have to be in a fixture. I've made a helper function for that:

    import pytest
    
    def ask_user_input(msg=''):
        """ Asks user to check something manually and answer a question
        """
        notification = "\n\n???\tANSWER NEEDED\t???\n\n{}".format(msg)
    
        # suspend input capture by py.test so user input can be recorded here
        capture_manager = pytest.config.pluginmanager.getplugin('capturemanager')
        capture_manager.suspendcapture(in_=True)
    
        answer = raw_input(notification)
    
        # resume capture after question have been asked
        capture_manager.resumecapture()
    
        logging.debug("Answer: {}".format(answer))
        return answer
    

提交回复
热议问题