python - Pytests 不从本地目录收集测试
问题描述
我一直在互联网上寻找答案。他们都告诉我要确保我完全按照你在下面看到的那样做。我实际上是在 Pytest 的在线课程中完成这一切的,但它不起作用。
ls
TestCheckout.py __init__.py __pycache__ pytest.ini
cat TestCheckout.py
def test_ConInstantiateCheckout():
co = CheckOut()
pytest
=================================================== test session starts ====================================================
platform darwin -- Python 3.7.4, pytest-5.2.0, py-1.8.0, pluggy-0.13.0
rootdir: /Users/ddow/dev/supermarket-kata
collected 0 items
================================================== no tests ran in 0.01s
有谁知道给了什么?任何帮助将不胜感激。
解决方案
pytest
遵循测试发现程序。您可以在此处查看详细信息。
对于您的特定情况,文件名应以 . 开头test_
或结尾_test.py
。所以重命名TestCheckout.py
为test_Checkout.py
会起作用。如果您不想更改名称,您可以明确提供文件名,如
user@qt01:~/folder$ pytest TestCheckout.py
============================================== test session starts ==============================================
platform linux -- Python 3.5.2, pytest-5.1.2, py-1.8.0, pluggy-0.12.0
sensitiveurl: .*
rootdir: /home/user/folder
plugins: needle-0.3.11, selenium-1.17.0, html-1.21.1, repeat-0.8.0, metadata-1.8.0, celery-4.3.0, base-url-1.4.1, variables-1.7.1
collected 1 item
TestCheckout.py . [100%]
=============================================== 1 passed in 0.03s ===============================================
user@qt01:~/folder$
推荐阅读
- jenkins - 流的结尾或文档分隔符应在第 21 行 (ssh)
- r - glmer:逻辑回归模型未能收敛
- javascript - 如何在 Graal-JS 中从 java 中获取 js 对象的字段和调用方法?
- c++ - 为什么我得到“string_view:没有这样的文件或目录”
- python - 我想在不同的时间创建线程
- ios - 如何使用 Appium 查找 iOS 自动化的应用 ID?
- javascript - Javascript xlink:href 本地 svg 图像
- python - 如何使用 python selenium 拖放元素
- asp.net-core - 每次需要实例时如何设置控制台应用程序不使用 GetService
- javascript - Strapi 自定义管理员不在远程服务器上工作