首页 > 解决方案 > 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

有谁知道给了什么?任何帮助将不胜感激。

标签: pythonpython-3.xpytest

解决方案


pytest遵循测试发现程序。您可以在此处查看详细信息。

对于您的特定情况,文件名应以 . 开头test_或结尾_test.py。所以重命名TestCheckout.pytest_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$


推荐阅读