Skip to main content

An energy estimation reporter for pytest

Project description

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

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.5.2.tar.gz (18.3 kB view details)

Uploaded Source

Built Distribution

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

pytest_energy_reporter-0.5.2-py3-none-any.whl (19.8 kB view details)

Uploaded Python 3

File details

Details for the file pytest_energy_reporter-0.5.2.tar.gz.

File metadata

  • Download URL: pytest_energy_reporter-0.5.2.tar.gz
  • Upload date:
  • Size: 18.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.12.2 Windows/10

File hashes

Hashes for pytest_energy_reporter-0.5.2.tar.gz
Algorithm Hash digest
SHA256 e3515d81ca067103f7766b622de47f737a85de94fb308f16a973c8f59a55ed90
MD5 35ced7ce313693ea887dba028eed13c9
BLAKE2b-256 ac08f403e403a05803356a3e97b6d91d3d0259fb3704615fbaf321d59cfd83ba

See more details on using hashes here.

File details

Details for the file pytest_energy_reporter-0.5.2-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_energy_reporter-0.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0726524fd8b40e1f80bf5ffd19de40756ced13a0888bbf1b5476c00a14cdcd8e
MD5 1972e0bf5cff339617b87610397c9040
BLAKE2b-256 b74815494a3a70683965fd5a844c062ebc793fb2949efa5e4151ee11ee9f9b87

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