Skip to main content

An energy estimation reporter for pytest

Project description

pytest energy reporter

The pytest energy reporter can be used to report on energy usage of code, by measuring tests.

Installation

To install pytest energy reporter, simply run:

pip install pytest_energy_reporter

Usage

The package is automatically enabled in pytest. To start measuring energy consumption, mark tests as energy test using:

import pytest

@pytest.mark.energy
def test_fn():

# Or define the exact number of iterations to measure
@pytest.mark.energy(n=3)
def test_fn():

# Or use the measurement directly
from pytest_energy_reporter.measurement import measure_energy

def test_fn():
  result = measure_energy(fn)
  assert result.energy_j < 200

The plugin exposes a few flags in pytest

Flag Argument Default Meaning
--energy-iterations int 3 Specify the number of iterations for the energy measurement.
--save-energy-report <none> False Whether to save the energy report.
--energy-report-path str 'reports/energy' The path to save the energy report in.

Contributing

Prerequistes

Make sure you have poetry installed.

Installation

To install the pytest energy reporter repository, run:

  1. Clone the repository
git clone git@github.com:delanoflipse/pytest-energy-reporter.git
  1. Clone subrepositories
git submodule init && git submodule update
  1. Install dependencies
poetry install
  1. (Temporary) (Only on windows) install wmi:
poetry run pip install pywin32

Usage

To develop the plugin, use:

poetry shell

And run the example test suite:

pytest --log-cli-level=DEBUG

Publishing

  1. Build the project:
poetry build
  1. Publish to pip (make sure you have credentials setup):
poetry publish

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_energy_reporter-0.4.0.tar.gz (3.3 MB view hashes)

Uploaded Source

Built Distribution

pytest_energy_reporter-0.4.0-py3-none-any.whl (3.4 MB 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