如何调用Pytest

如何调用Pytest

在模块中运行测试

pytest test_mod.py

在目录中运行测试

pytest testing/

通过关键字表达式运行测试

pytest -k 'MyClass and not method'

这将运行包含与给定字符串表达式(不区分大小写)匹配的名称的测试,其中可以包括使用文件名、类名和函数名作为变量的 Python 运算符。上面的例子会运行TestMyClass.test_something ,但不会TestMyClass.test_method_simple。在 Windows 上运行时使用""代替in 表达式''

通过集合参数运行测试

传递相对于工作目录的模块文件名,后跟由字符分隔的类名和函数名等说明符::,以及包含在[].

要在模块内运行特定测试:

pytest tests/test_mod.py::test_func

要运行类中的所有测试:

pytest tests/test_mod.py::TestClass

指定具体的测试方法:

pytest tests/test_mod.py::TestClass::test_method

指定测试的特定参数化:

pytest tests/test_mod.py::test_func[x1,y2]

通过标记表达式运行测试

pytest -m slow

将运行所有用装饰器装饰的测试@pytest.mark.slow

有关详细信息,请参阅标记

从包运行测试

pytest --pyargs pkg.testing

这将导入pkg.testing并使用其文件系统位置来查找并运行测试。

posted @ 2024-03-18 14:12  乐乐乐乐乐乐樂  阅读(23)  评论(0)    收藏  举报
jQuery火箭图标返回顶部代码