Skip to main content

pytest plugin to instrument tests

Project description

PyPI version Python versions See Build Status on Circle CI MIT license

A pytest plugin to instrument tests and write the resulting records to file


  • json file with one record for each setup/call/teardown of each test containing:

    • session id and record id (UUIDs generated by plugin)
    • node_id (pytest’s nodeid)
    • when (setup, call or teardown)
    • outcome (passed, failed or skipped)
    • start, stop and duration
    • labels (array) and tags (object) via @pytest.mark.instrument() decorator
    • fixtures
  • hooks to edit labels, tags and fixtures before the record is written to file


  • Python 3.6 or higher
  • pytest 5.1.0 or higher


You can install “pytest-instrument” via pip from PyPI:

$ pip install pytest-instrument


Run your tests with:

$ pytest --instrument

An ./artifacts directory will be created if it doesn’t exist yet. For each pytest session one .json file will be written to that directory.

Labels and tags

You can add labels and tags to tests with the plugin’s mark decorator:

@pytest.mark.instrument("a_label", my_tag="tagged")

All args, such as “a_label”, are put in the json array labels. All kwargs, such as my_tag=”tagged”, are put in the json object tags.


  • pytest_instrument_labels: edit list of labels after they’ve been parsed by the plugin
  • pytest_instrument_tags: edit dictionary of tags after they’ve been parsed by the plugin
  • pytest_instrument_fixtures: edit list of fixtures after they’ve been parsed by the plugin


Consult the changelog for fixes and enhancements of each version.


Please use the GitHub issue tracker to submit bugs or request features.


Contributions are welcome. Tests can be run with tox, please ensure black code formatting and good test coverage before you submit a pull request.


Distributed under the terms of the MIT license, “pytest-instrument” is free and open source software


Thank you to Maaret Pyhäjärvi for inspiring this plugin by sharing the story of how her team started instrumenting tests at TestCraftCamp 2019.

This pytest plugin was generated with Cookiecutter along with @hackebrot’s cookiecutter-pytest-plugin template.

Project details

Release history Release notifications

Download files

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

Files for pytest-instrument, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size pytest_instrument-0.1.0-py3-none-any.whl (7.5 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size pytest-instrument-0.1.0.tar.gz (5.3 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page