Package: pytest-influxdb
Influxdb Pytest PluginInfluxdbPytestPlugin designed for reporting test results to theInfluxDBand provide with the live test results report which can be later integrated with a reporting tool.
It’s developed as pytest plugin and distributed viapypi.Table of ContentsAbout this documentationUsageAdd custom fields as an additional dataSend attachmentAbout this documentationWelcome to the Influxdb Pytest Plugin documentation!This style guide provides set of editorial guidelines for anyone using Influxdb Pytest Plugin.UsageInstallationpip install pytest-influxdb-pluginLaunchingTo run a test with pytest-influxdb-plugin, the ‘–pytest-influxdb’ flag should be provided.pytest -sv –pytest-influxdbPrepare the config filepytest.iniin root directory of tests and/or call next to the run command the mandatory config variables which are mentioned below:The next mandatory fields should be mentioned inpytest.inior run through command line without ‘–’ prefix:--influxdb_host- host/url of the influxdb--influxdb_name- name of influxdb tableAnd here are the optional fields:--influxdb_port- port of the influxdb--influxdb_user- username of influxdb user--influxdb_password- password of influxdb user--influxdb_project- project name--influxdb_version- custom version of project--influxdb_merged- merge configuration--influxdb_run_id- run id (Can be passed as CI variable)Example ofpytest.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>Add custom fields as an additional dataAdd custom fields for test resultFor adding custom fields as an additional data for test result the code like below should be added in conftest.py.Example 1:@pytest.fixture(scope='function',autouse=True)deftest_suite(request):frominfluxdb_pytest_pluginimportTestResultDTOtest_result_dto=TestResultDTO()test_name=request.node.nodeidTestResultDTO.set_tag_values(test_result_dto,test_name,{'tag1':'tag_value1','tag2':'tag_value2'})TestResultDTO.set_field_values(test_result_dto,test_name,{'field1':'field_value1','field2':'field_value2'})Add custom fields for suite resultFor adding custom fields as an additional data for suite result thepytest_terminal_summarypytest plugin like below in 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'})yieldExample 2:
Add custom fields via--influxdb_valuesconfig, just fill the below template and set as--influxdb_valuesconfig:{"fields":{"test_result":{},"suite_result":{}},"tags":{"test_result":{},"suite_result":{}}}Send screenshot as attachmentFor sending the screenshot to the influxdb, thescreenshot_urlfixture should be used in function scope like below:Example 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()Example 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))