Pytest - 总结

在这个 pytest 教程中,我们涵盖了以下领域 −

  • 正在安装 pytest..
  • 识别测试文件和测试函数。
  • 使用 pytest –v 执行所有测试文件。
  • 使用 pytest <filename> -v 执行特定文件。
  • 通过匹配 pytest -k <substring> -v 的子字符串执行测试。
  • 执行基于标记 pytest -m <marker_name> -v 的测试。
  • 使用@pytest.fixture 创建固定装置。
  • conftest.py 允许从多个文件访问装置。
  • 使用@pytest.mark.parametrize 对测试进行参数化。
  • 使用 @pytest.mark.xfail 进行 Xfailing 测试。
  • 使用@pytest.mark.skip 跳过测试。
  • 使用 pytest --maxfail = <num> 在 n 次失败时停止测试执行。
  • 使用 pytest -n <num> 并行运行测试。
  • 使用 pytest -v --junitxml = "result.xml" 生成结果 xml。