@songying
2018-08-19T19:32:28.000000Z
字数 859
阅读 1203
pytest
python -m pytest [...]
该命令等价于直接pytest []
, 不过通过python调用会将当前路径加到sys.path
中。
Exit code 0: 所有测试完美通过
Exit code 1: 一些测试失败
Exit code 2: 用户中断test
Exit code 3: Internal error happened while executing tests
Exit code 4: pytest command line usage error
Exit code 5: No tests were collected
pytest --version
pytest --fixtures # show available builtin function arguments
pytest -h
pytest -x # 在出现第一个测试失败之后立即停止
pytest --maxfail=2 # stop after two failures
pytest test_mod.py # run tests in a module
pytest testing/ # run tests in a directory
pytest -k "MyClass and not method" # Run tests by keyword expressions
pytest test_mod.py::test_func # To run a specific test within a module
pytest test_mod.py::TestClass::test_method
pytest -m slow # run all tests which are decorated with the @pytest.mark.slow decorator.
pytest --pyargs pkg.testing # Run tests from packages