1.pytest -h 查看pytest常用命令
E:\myproj\pytest_demo>pytest -h usage: pytest [options] [file_or_dir] [file_or_dir] [...] positional arguments: file_or_dir general: -k EXPRESSION only run tests which match the given substring expression. An expression is a python evaluatable expression where all names are substring-matched
...以下略
2.pytest -vs(-v是啰嗦模式,啥信息都显示;-s允许测试运行时输出任何符合标准的输出流信息,例如代码里面的print)
执行结果: E:\myproj\pytest_demo>pytest -vs ================================================================================== test session starts ================================================================================== platform win32 -- Python 3.6.5, pytest-5.1.2, py-1.8.0, pluggy-0.12.0 -- e:\soft\python\python36\python.exe cachedir: .pytest_cache rootdir: E:\myproj\pytest_demo, inifile: pytest.ini, testpaths: ./testcases collected 9 items testcases/test_02.py::test_1 FAILED # FAILED指测试失败 testcases/test_02.py::test_2 b PASSED # 指测试通过 testcases/test_02.py::test_3 c PASSED testcases/test_fix.py::Test1::test_s1[\u6d4b\u8bd5-\u6d4b\u8bd5] 测试 PASSED testcases/test_fix.py::Test1::test_s2 用例2:不需要登录,操作222 PASSED testcases/test_fix.py::Test1::test_s3 登录系统 用例3:登录之后其它动作333 PASSED testcases/test_fix.py::Test2::test_s4 登录系统 用例4:登录之后其它动作444 PASSED testcases/test_fix.py::Test2::test_s5 用例5:不需要登录,操作555 PASSED testcases/test_fix.py::Test2::test_s6 用例6:登录之后其它动作666 PASSED ======================================================================================= FAILURES ======================================================================================== ________________________________________________________________________________________ test_1 _________________________________________________________________________________________ def test_1(): a = 2 > assert a == 1 E assert 2 == 1 E -2 E +1 testcases\test_02.py:9: AssertionError ============================================================================== 1 failed, 8 passed in 0.29s ==============================================================================
3.pytest --lf --ff
--lf, --last-failed rerun only the tests that failed at the last run (or # 运行上次失败的用例,如果没有失败会重新跑
all if none failed)
--ff, --failed-first run all tests but run the last failures first. This
may re-order tests and thus lead to repeated fixture
setup/teardown
4.pytest -x : exit instantly on first error or failed test
5.
6.
8.pytest -m “mark标记名”:运行指定标记的测试用例
9.pytest -k