摘要
-
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所在文件地址下查找用例去執行