摘要
-
pytest运行后出现的状态码
-
pytest运行方式
-
pytest操作手册:点击跳转
pytest 运行中出现的6中状态码
Exit code 0
: All tests were collected and passed successfully
Exit code 1
: Tests were collected and run but some of the tests failed
Exit code 2
: Test execution was interrupted by the user
Exit code 3
: Internal error happened while executing tests
Exit code 4
: pytest command line usage error
Exit code 5
: No tests were collected
文档地址
Stopping after the first (or N) failures
pytest -x
# stop after first failure
pytest --maxfail=2
# stop after two failures
Specifying tests / selecting tests
Pytest supports several ways to run and select tests from the command-line.
运行一个模块下的用例
pytest test_mod.py
运行一个路径下的用例
pytest testing/
运行匹配特定规则的用例
pytest -k "MyClass and not method"
该规则将运行TestMyClass.test_something下的用例,但是不运行TestMyClass.test_method_simple下的用例
Run tests by node ids
方法一:运行模块下的指定函数
pytest test_mod.py::test_func
方法二:运行模块下的指定函数
pytest test_mod.py::TestClass::test_method
运行带标记表达式的用例
pytest -m slow
将运行所有带诸如 @pytest.mark.slow 标志的用例
Run tests from packages
pytest --pyargs pkg.testing
This will import pkg.testing and use its filesystem location to find and run tests from
这个命令将导入pkg.testing ,然后从pkg.testing所在文件地址下查找用例去执行