用于XDB和pytest集成的插件。
pytest-influxdb的Python项目详细描述
Influxdb Pytest插件
InfluxdbPytest插件,用于向InfluxDB报告测试结果 并提供实时测试结果报告,该报告可稍后与报告工具集成。 它是作为pytest插件开发的,并通过pypi发布。在
关于本文档
欢迎使用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_summary
pytest插件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))
- 项目
标签: