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