Pytest 简明教程

Identifying Test files and Test Functions

在不提及文件名的情况下运行 pytest 将运行当前目录和子目录中所有格式为 test_ .py* 或 *_test.py 的文件。Pytest 会自动将这些文件识别为测试文件。我们 can 显式提及其他文件名来让 pytest 运行它们。

Pytest 要求测试函数的名称以 test 开头。函数名称不属于格式 test * 的不被 pytest 视为测试函数。我们 cannot 显式声明 pytest 将任何名称不以 test 开头的函数视作测试函数。

我们将在后续章节中了解测试的执行。