首页 > 解决方案 > 从终端运行命令时收集了 0 个项目

问题描述

我使用下面的代码只是为了检查我的pytest功能:

class test_001:

    def test_addition(self):
        assert 1 + 1 == 2

在运行命令时:

pytest -v -s testCases/testme.py

它总是显示Collected 0 items
请告诉我我做错了什么。
谢谢并恭祝安康

标签: pythonautomationpytest

解决方案


查看pytest 文档上的测试发现,默认是查找名为 test_*.py 或 *_test.py 的文件。如果你有一堂课,那么该堂课应该开始测试。

因此,如果您重命名文件 testCases/test_me.py 并重命名类 IE:

class Test_001:
    def test_addition(self):
        assert 1+1 == 2

然后pytest会找到它


推荐阅读