用于XDB和pytest集成的插件。

pytest-influxdb的Python项目详细描述


Influxdb Pytest插件

InfluxdbPytest插件,用于向InfluxDB报告测试结果 并提供实时测试结果报告,该报告可稍后与报告工具集成。 它是作为pytest插件开发的,并通过pypi发布。在

Release StatusDownloads

关于本文档

欢迎使用Influxdb Pytest插件文档!在

这个风格指南为任何使用Influxdb Pytest插件的人提供了一套编辑指南。在

使用

安装

pip install pytest-influxdb-plugin

启动

要使用pytest influxdb plugin运行测试,应提供“-pytest influxdb”标志。在

pytest -sv –pytest-influxdb

准备测试根目录中的配置文件pytest.ini,和/或在run命令旁边调用下面提到的强制配置变量:

下一个必填字段应在pytest.ini中提及,或在不带“-”前缀的命令行中运行:

  • --influxdb_host-influxdb的主机/url
  • --influxdb_name-influxdb表的名称

以下是可选字段:

  • --influxdb_port-流入端口db
  • --influxdb_user-influxdb user的用户名
  • --influxdb_password-influxdb用户的密码
  • --influxdb_project-项目名称
  • --influxdb_version-项目的自定义版本
  • --influxdb_merged-合并配置
  • --influxdb_run_id-运行id(可以作为CI变量传递)

pytest.ini示例:

[pytest]
influxdb_host = <DB_HOST>
influxdb_port = <DB_PORT>
influxdb_name = <DB_NAME>
influxdb_user = <DB_USER>
influxdb_password = <DB_PASSWORD>
influxdb_project = <PROJECT_NAME>
influxdb_version = <PROJECT_NAME>
influxdb_run_id = <RUN_ID>

添加自定义字段作为附加数据

为测试结果添加自定义字段 为了添加自定义字段作为测试结果的附加数据,应该添加如下代码conftest.py. 在

例1:

^{pr2}$

为套件结果添加自定义字段 要添加自定义字段作为suiteresult的附加数据,请使用下面的pytest_terminal_summarypytest插件conftest.py. 在

@pytest.hookimpl(hookwrapper=True)defpytest_terminal_summary(config,terminalreporter):frominfluxdb_pytest_pluginimportSuiteResultDTOsuite_result_dto=SuiteResultDTO()SuiteResultDTO.set_tag_values(suite_result_dto,{'tag1':'tag_value1'})SuiteResultDTO.set_field_values(suite_result_dto,{'field1':'field_value1'})yield

例2: {14{14>通过下面的自定义}填充}字段:

{"fields":{"test_result":{},"suite_result":{}},"tags":{"test_result":{},"suite_result":{}}}

将截图作为附件发送

为了将屏幕截图发送到influxdb,应该在如下函数范围内使用screenshot_url夹具:

例1:

@pytest.fixture(scope="function")defchrome_driver_init(request,screenshot_url,pytestconfig):chrome_driver=webdriver.Chrome()request.cls.driver=chrome_driveryieldifrequest.node.rep_call.failedandpytestconfig.getoption('--pytest-influxdb'):screenshot_link='URL_EXAMPLE'chrome_driver.save_screenshot(screenshot_link)screenshot_url(screenshot_link)chrome_driver.close()

例2:

@pytest.hookimpl(tryfirst=True,hookwrapper=True)defpytest_runtest_makereport(item,call):outcome=yieldrep=outcome.get_result()ifrep.when=='call':try:screenshot_path=web_client.current.save_screenshot("Screenshot link")item.user_properties=("screenshot_url",screenshot_path)# web_driver.save_screenshot and other magic to add screenshot to your reportexceptExceptionase:print('Exception while screen-shot creation: {}'.format(e))

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java是否可以在数组中打印一行元素?   Java框架   javadom4j:用<any>标记包装所有元素   java JMH,微基准代码的一部分   JavaFX拖放TableCell   Java中的volatile关键字   如何在JAVA中使用ApachePOI删除Excel中的警告?   java Android firebase数据库权限被拒绝,尽管用户已登录   eclipse如何在类文件中控制按钮。java文件?   java Android如何从API(rottentomatoes)JSON获取url/链接   java Proguard和两个使用相同安卓库的项目。广播。ClassNotFoundException   Oracle DomParser的java解析XXE   java组织。冬眠cfg。添加注释类所在的包的配置   有没有办法通过JNI将Java数组传递给C而不复制它?   java从XML文件加载请求代码   java表单布局调用JColorChooser   java如何使用Spring boot在neo4j中保存多边形   获取java中的URL参数并从该URL提取特定文本