Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 暂停PyTest并等待用户输入_Python_Python 3.x_Pytest - Fatal编程技术网

Python 暂停PyTest并等待用户输入

Python 暂停PyTest并等待用户输入,python,python-3.x,pytest,Python,Python 3.x,Pytest,如何暂停正在运行的测试并等待用户输入 我有一个非常规的测试(Python3,pytest),在继续测试之前,我想“暂停”向用户(我)询问id代码 我知道这不是标准,我想知道如何解决这个问题 示例测试: def test_oauth_flow(self): url_jwt = auth(id=client_id, scope=scope) id_code = webbrowser.open_new(url_jwt) # pause wait

如何暂停正在运行的测试并等待用户输入

我有一个非常规的测试(Python3,pytest),在继续测试之前,我想“暂停”向用户(我)询问id代码

我知道这不是标准,我想知道如何解决这个问题

示例测试:

    def test_oauth_flow(self):
        url_jwt = auth(id=client_id, scope=scope)
        id_code = webbrowser.open_new(url_jwt)
        # pause wait for user input.
        # use code to complete flow etc....
        auth = auth(code)
        assert auth is 1

好的,这将始终取决于您测试的内容,但我的建议是针对外部API运行ContractTests,并记录对后者的响应,以使这些数据可用于您的功能测试

要记录响应,您可以使用vcr,它是一个Ruby工具:,但也有一个python实现(我没有使用它)

从,这是可能的,但pytest的默认捕获需要拨回
sys

$ pytest --capture=sys ./tests/
然后,此测试功能将在用户提示下停止测试:

def fd_input(prompt):
    with os.fdopen(os.dup(1), "w") as stdout:
        stdout.write("\n{}? ".format(prompt))

    with os.fdopen(os.dup(2), "r") as stdin:
        return stdin.readline()

模拟输入并让测试自动运行可能是一个更好的主意。@ReblochonMasque我正在对外部API运行功能测试。我需要一个密码才能继续。我明白了。。。你能模拟或存根API吗?@ReblochonMasque不幸不能。我需要运行他们的开发系统。否则,我将不得不构建自己的开放id服务器来模拟它。这将使您的测试依赖于一个人,您真的想要吗?我讨厌一个测试套件,它需要我坐下来输入一些东西才能继续。此外,您可以忘记在CI服务器上自动运行等。自动获取您必须输入的这些信息不是更好吗?当然,您可以编写一些代码来查询OpenID服务器的凭据,然后在测试中通过这些凭据。