Skip to main content

An Energy Reporter Plugin for pytest

The pytest_energy_reporter is a pytest plugin can be used to report on energy and power consumption usage of code, by easily integrating in existing test suites.

It relies on the Energy Consumption Reporter to get approximations for energy measurements.

Installation

To install pytest energy reporter, simply run:

pip install pytest_energy_reporter

Usage

The package is automatically enabled in pytest. If it is not, make sure to read the documentation on how to enable plugins 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():
  measure = measure_energy(fn)
  assert measure.energy_j < 200

# Or use the measurement and the result of the method
from pytest_energy_reporter.measurement import measure

def test_fn():
  measure, result, error = measure(fn, n=2)
  assert result == # ...
  assert error == None
  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 Feature flag to save the energy report.
--energy-report-path str 'reports/energy' The path to save the energy report in.
--energy-offset-zero <none> False Feature flag to compensate the power measurement by the power draw of zero utilization.

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. Install dependencies
poetry install

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

Metadata

Release files for pytest_energy_reporter 0.5.2

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

Source distribution (sdist)

Source distribution for pytest_energy_reporter 0.5.2
File Size Uploaded Provenance
pytest_energy_reporter-0.5.2.tar.gz 18.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest_energy_reporter 0.5.2
File Interpreter ABI Platform
pytest_energy_reporter-0.5.2-py3-none-any.whl Python 3 none any Details

Total release size: 38.1 kB

Release files / pytest_energy_reporter-0.5.2.tar.gz

Download URL pytest_energy_reporter-0.5.2.tar.gz
Size 18.3 kB
Tags Source
SHA-256 checksum
How to use checksums
e3515d81ca067103f7766b622de47f737a85de94fb308f16a973c8f59a55ed90
BLAKE2b-256 checksum
How to use checksums
ac08f403e403a05803356a3e97b6d91d3d0259fb3704615fbaf321d59cfd83ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.12.2 Windows/10

Release files / pytest_energy_reporter-0.5.2-py3-none-any.whl

Download URL pytest_energy_reporter-0.5.2-py3-none-any.whl
Size 19.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0726524fd8b40e1f80bf5ffd19de40756ced13a0888bbf1b5476c00a14cdcd8e
BLAKE2b-256 checksum
How to use checksums
b74815494a3a70683965fd5a844c062ebc793fb2949efa5e4151ee11ee9f9b87
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.12.2 Windows/10

Security for pytest_energy_reporter 0.5.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

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