gpt4 book ai didi

python - pytest收集了0个项目

转载 作者:行者123 更新时间:2023-12-03 11:59:46 25 4
gpt4 key购买 nike

我有一个套接字程序-2个脚本,服务器和客户端。在服务器端,我有很多功能。我要测试这些功能。我是python的新手。找到了一个叫做pytest的东西。因此,对于服务器端的所有功能,我都做了类似的事情。

def fun(a):
// fn definition
return b
def test_fun():
assert fun(test_case) == "expected value"

我将此服务器脚本命名为test_server.py并导入了pytest。我也在客户端导入了pytest并将脚本重命名为test_client.py然后当我使用

py.test test_server.py



接着

py.test test_client.py



在服务器端,它说收集了0个项目,仅此而已。它没有收集任何东西。任何想法,我要去哪里错了。顺便说一句,我尝试了简单的python代码。 pytest工作正常。是pytest无法与套接字编程一起使用,还是我在做任何错误?同样,不使用pytest,代码也不会出错。当我这样做时,它工作得很好

python test_server.py



接着,

python test_client.py

最佳答案

如果要测试客户端功能,则应实际模拟服务器响应。如果要为客户端运行一些集成测试。然后使用以下命令启动服务器:

python test_server.py

并以以下方式运行客户端测试:
py.test test_client.py

py.test只运行名称以test_开头的函数,因此我猜测您的服务器甚至都不以pytest开头。

关于python - pytest收集了0个项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39894566/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com