Skip to main content

Collects tests metadata for future analysis, easy to extend for any data store

Project description

Pytest-stats

This library is collecting metadata about your test executions, and enables you to send it to a datastore of your liking.

Architecture

The library is designed in a hexagonal architecture in mind - separating data collection and reporting. There are two main parts to the code - metadata collection and reporting. the collection engine stores the metadata in pytest's stash (for session and for test) and uses pytest built-in hooks in order to populate the data and trigger the reporting. The reporting part is allowing reporters to register, then delegates the actual work to the registered reporters, enabling easy customization.

Implementation guide

In order to include pytest-stats capabilities in your code, all you need to do is to install the package pip install pytest-stats.
However, this will only provide you with a text report provided by the built-in DefaultTextReporter. In order to store the data in your own DB you'll need to:

  1. Create a new reporter (inherit the abstract ResultsReporter class)
  2. Register an instance of your reporter using the provided new hook pytest_stats_register_reporters.
    Example:
@pytest.hookimpl()
def pytest_stats_register_reporters(reporters:'ReportersRegistry'):
    reporters.register(MyReporter())

Implementation details

how is data collected and reported?

Most data is collected by hooking the following pytest-provided hooks:

  • pytest_sessionstart
  • pytest_sessionfinish
  • pytest_runtest_protocol
  • pytest_runtest_makereport
  • pytest_exception_interact

New hooks available

  • pytest_stats_register_reporters: used to register a new reporter. More than one reporter can be registered at the same hook.
    Invoked as part of pytest_configure
  • pytest_stats_env_data: Enables adding custom environment information to the session data.
    Invoked as part of pytest_sessionstart

Utility functions

  • get_test_session_data(session: 'Session') -> TestSessionData - can be used to fetch the session data in an arbitrary location
  • get_test_item_data(item: 'Item') -> TestItemData - can be used to fetch the current test data in arbitrary location. For instance, one can call get_test_item_data(item=request.node).foo="bar"

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_stats-1.0.0.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_stats-1.0.0-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file pytest_stats-1.0.0.tar.gz.

File metadata

  • Download URL: pytest_stats-1.0.0.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Linux/6.5.0-1022-azure

File hashes

Hashes for pytest_stats-1.0.0.tar.gz
Algorithm Hash digest
SHA256 373af08da6839623f44a6ed1ee1d06f9314e29fc7a80963d402675914b515b07
MD5 75e4bae67922283b6d60b37fb3863715
BLAKE2b-256 a881171369a39c0f5ba029b35ec58013804fe89605875e35e8acc6b23eb7a127

See more details on using hashes here.

File details

Details for the file pytest_stats-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pytest_stats-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Linux/6.5.0-1022-azure

File hashes

Hashes for pytest_stats-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5e02c16bcb5fcef075f7ca42a4504a192d1b52e66ca37ae65bdc794e915a3f23
MD5 9f4e3a695796341cc0d76f8cdef3cee4
BLAKE2b-256 8cd78618f39b1de14af968d0af734b94a424a8dc94b073cc06b1081f1f5b730e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page