09、pytest多种调用方式

官方用例

python 复制代码
# content of myivoke.py
import sys
import pytest

class MyPlugin:
    def pytest_sessionfinish(self):
        print("*** test run reporting finishing")
        
if __name__ == "__main__":
    sys.exit(pytest.main(["-qq"],plugins=[MyPlugin()]))
python 复制代码
# content of other_invoke.py
import pytest

if __name__ == "__main__":
    retcode = pytest.main()
    print(retcode)
python 复制代码
# content of test_invok_01.py

def test_invok_01():
    print("test_invok_01 was invoked")
    assert 0

解读与实操

  • 通过pytest命令行调用
  • 通过python命令行调用
  • python代码中调用

应用场景

  • 个人调试或Jenkins调用,可使用python或pytest命令行
  • 测试平台,集成pytest时,可以在Python代码中调用pytest
相关推荐
血小板要健康10 小时前
Spring IoC & DI (下)
java·前端·spring boot·后端·spring·servlet·java-ee
测试人社区—66791 天前
2025区块链分层防御指南:AI驱动的安全测试实战策略
开发语言·驱动开发·python·appium·pytest
我送炭你添花2 天前
pytest 入门指南:从零开始掌握 Python 测试框架的核心概念与使用方法
chrome·python·pytest
though the night2 天前
Python UI 自动化测试框架搭建demo(Selenium+Pytest 版)
自动化测试·selenium·测试工具·pytest
我送炭你添花2 天前
软件测试为何不可或缺?——以复杂宏系统与 PTZ 控制为例,深度解析 pytest 的实战价值与不可替代性
python·测试工具·pytest
taihexuelang3 天前
jenkins 部署java项目
java·servlet·jenkins
想你依然心痛3 天前
时序数据库选型指南:开启高效数据管理之旅
struts·servlet·时序数据库
我的xiaodoujiao3 天前
使用 Python 语言 从 0 到 1 搭建完整 Web UI自动化测试学习系列 44--Pytest框架钩子函数
python·学习·测试工具·pytest
给你一页白纸3 天前
将分散的Pytest测试脚本统一接入测试平台:FastAPI改造方案详解
python·pytest·接口自动化·测试平台
问道飞鱼4 天前
【自动化测试】 pytest 结合 Playwright 实现页面元素在两个区域间拖拽
pytest·拖拽·playweight