pytest 收集 0 项
pytest collecting 0 items
我有一个套接字程序 - 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 只有 运行s 名称以 test_ 开头的函数,所以我猜你的服务器甚至没有以 pytest 开头。
我有一个套接字程序 - 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 只有 运行s 名称以 test_ 开头的函数,所以我猜你的服务器甚至没有以 pytest 开头。