Skip to main content

Influxdb Pytest Plugin

Pytest plugin designed for reporting test results to the ‘InfluxDB’.

Table of Contents

  • About this documentation

  • Usage

  • Add custom fields as an additional data(test level and suite level)

  • Send attachment

About this documentation

Welcome to the Influxdb Pytest Plugin documentation!

This style guide provides set of editorial guidelines for anyone using Influxdb Pytest Plugin.

Usage

Installation

pip install influxdb-pytest-plugin

Launching

To run a test with influxdb-pytest-plugin, the ‘–influxdb-pytest’ flag should be provided.

pytest -sv –influxdb-pytest

Prepare the config file pytest.ini in 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 in pytest.ini or run through command line without ‘–’ prefix:

  • --influxdb_host - host of the influxdb

  • --influxdb_name - name of influxdb table

And 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_run_id - run id (Can be passed as CI variable)

Example of 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>

Add custom fields as an additional data

Add custom fields for test result For 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)
def test_suite(request):
    from influxdb_pytest_plugin import TestResultDTO
    test_result_dto = TestResultDTO()
    test_name = request.node.nodeid
    TestResultDTO.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 result For adding custom fields as an additional data for suite result the pytest_terminal_summary pytest plugin like below in conftest.py.

@pytest.hookimpl(hookwrapper=True)
def pytest_terminal_summary(config, terminalreporter):
    from influxdb_pytest_plugin import SuiteResultDTO
    suite_result_dto = SuiteResultDTO()
    SuiteResultDTO.set_tag_values(suite_result_dto, {'tag1': 'tag_value1'})
    SuiteResultDTO.set_field_values(suite_result_dto, {'field1': 'field_value1'})
    yield

Example 2: Add custom fields via --influxdb_values config, just fill the below template and set as --influxdb_values config:

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

Send screenshot as attachment

For sending the screenshot to the influxdb, the screenshot_url fixture should be used in function scope like below:

Example 1:

@pytest.fixture(scope="function")
def chrome_driver_init(request, screenshot_url, pytestconfig):
chrome_driver = webdriver.Chrome()
request.cls.driver = chrome_driver
yield
if request.node.rep_call.failed and pytestconfig.getoption('--influxdb-pytest'):
    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)
def pytest_runtest_makereport(item, call):
    outcome = yield
    rep = outcome.get_result()
    if rep.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 report
        except Exception as e:
            print('Exception while screen-shot creation: {}'.format(e))

Release files for influxdb-pytest-plugin 0.2.57

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for influxdb-pytest-plugin 0.2.57
File Size Uploaded
influxdb_pytest_plugin-0.2.57.tar.gz 9.1 kB Details

Release files / influxdb_pytest_plugin-0.2.57.tar.gz

Download URL influxdb_pytest_plugin-0.2.57.tar.gz
Size 9.1 kB
Tags Source
SHA-256 checksum
How to use checksums
49f9d87194fd07f46d0a4d64b9ef3470cd3de21a4d45d5e42c778740d91b416f
BLAKE2b-256 checksum
How to use checksums
330c5c752cfd1c7e0a158714f69a179255c8fca1682d979326ff54979108cfa2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.9
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page