Skip to main content

record pytest session characteristics per test item (coverage and duration) into a persistent file and use them in your own plugin or script.

Project description

pytest_donde

pytest_donde records per-test-item coverage and duration into a persistent file and offers an API to access this data in your plugins or scripts.

details

create persistent record

python -m pytest --donde=/path/to/src

This creates a donde.json file with the following information for every test item:

  • run duration (sec),
  • covered lines of code w.r.t. /path/to/src

by wrapping pytest-cov, evaluating its output, and putting this together with collected test item durations.

access record

from pytest_donde import Outcome
outcome = Outcome.from_file('donde.json')

A demo example (which is trivial, because it uses only durations, not coverage):

class PluginPreferFastest:

    def __init__(self, path_input):
        self.outcome = Outcome.from_file(path_input)

    def pytest_collection_modifyitems(self, session, config, items):

        def key(item):
            try:
                return self.outcome.nodeid_to_duration(item.nodeid)
            except KeyError:
                # test is unknown to the donde.json record,
                # possibly it was skipped there or was added after the record was made
                # we prefer it to run at the beginning
                return 0.0

        items[:] = sorted(items, key=key)

install

python -m pip install pytest-donde

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_donde-1.0.0.tar.gz (8.8 kB view hashes)

Uploaded Source

Built Distribution

pytest_donde-1.0.0-py3-none-any.whl (7.6 kB view hashes)

Uploaded Python 3

Supported by

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