[关闭]
@songying 2018-08-19T19:32:28.000000Z 字数 859 阅读 1203

2. Usage and Invocations

pytest


  1. python -m pytest [...]

该命令等价于直接pytest [], 不过通过python调用会将当前路径加到sys.path中。

退出codes

  1. Exit code 0: 所有测试完美通过
  2. Exit code 1: 一些测试失败
  3. Exit code 2: 用户中断test
  4. Exit code 3: Internal error happened while executing tests
  5. Exit code 4: pytest command line usage error
  6. Exit code 5: No tests were collected

常见命令

  1. pytest --version
  2. pytest --fixtures # show available builtin function arguments
  3. pytest -h

Stopping after the first (or N) failures

  1. pytest -x # 在出现第一个测试失败之后立即停止
  2. pytest --maxfail=2 # stop after two failures

Specifying tests / selecting tests

  1. pytest test_mod.py # run tests in a module
  2. pytest testing/ # run tests in a directory
  3. pytest -k "MyClass and not method" # Run tests by keyword expressions
  4. pytest test_mod.py::test_func # To run a specific test within a module
  5. pytest test_mod.py::TestClass::test_method
  6. pytest -m slow # run all tests which are decorated with the @pytest.mark.slow decorator.
  7. pytest --pyargs pkg.testing # Run tests from packages

Modifying Python traceback printing

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注