Pytest 总结
在这个pytest教程中,我们涵盖了以下几个方面:
- 安装pytest。
- 识别测试文件和测试函数。
- 使用pytest -v执行所有测试文件。
- 使用
pytest <filename> -v
执行特定文件。 - 通过子串匹配执行测试 pytest -k <子串> -v.
- 基于标记执行测试 pytest -m
-v. - 使用@pytest.fixture创建夹具。
- conftest.py允许从多个文件访问固定装置。
- 使用@pytest.mark.parametrize对测试进行参数化。
- 使用@pytest.mark.xfail.Xfail测试失败。
- 使用@pytest.mark.skip跳过测试。
- 使用
pytest --maxfail = <num>
在n次失败时停止测试执行。 - 使用
pytest -n <num>
并行运行测试。 - 使用pytest -v –junitxml = “result.xml “生成结果xml。