pytest_energy_reporter


Namepytest_energy_reporter JSON
Version 0.5.2 PyPI version JSON
download
home_pageNone
SummaryAn energy estimation reporter for pytest
upload_time2024-03-28 22:35:26
maintainerDelano Flipse
docs_urlNone
authorDelano Flipse
requires_python<4.0,>=3.10
licenselicense.txt
keywords pytest energy reporter
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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](https://github.com/aron-hoogeveen/energy-consumption-reporter) to get approximations for energy measurements.

## Installation

To install pytest energy reporter, simply run:

```bash
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](https://docs.pytest.org/en/stable/how-to/plugins.html). To start measuring energy consumption, mark tests as energy test using:

```python
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](https://python-poetry.org/) installed.

### Installation

To install the pytest energy reporter repository, run:

1. Clone the repository
```bash
git clone git@github.com:delanoflipse/pytest-energy-reporter.git
```

2. Install dependencies 
```bash
poetry install
```
### Usage

To develop the plugin, use:

```bash
poetry shell
```

And run the example test suite:

```bash
pytest --log-cli-level=DEBUG
```

### Publishing

1. Build the project:

```bash
poetry build
```
2. Publish to pip (make sure you [have credentials setup](https://python-poetry.org/docs/repositories/#configuring-credentials)):
```bash
poetry publish
```
            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pytest_energy_reporter",
    "maintainer": "Delano Flipse",
    "docs_url": null,
    "requires_python": "<4.0,>=3.10",
    "maintainer_email": "delanoflipse@gmail.com",
    "keywords": "pytest, energy, reporter",
    "author": "Delano Flipse",
    "author_email": "delanoflipse@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/ac/08/f403e403a05803356a3e97b6d91d3d0259fb3704615fbaf321d59cfd83ba/pytest_energy_reporter-0.5.2.tar.gz",
    "platform": null,
    "description": "# An Energy Reporter Plugin for pytest\n\nThe `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.\n\nIt relies on the [Energy Consumption Reporter](https://github.com/aron-hoogeveen/energy-consumption-reporter) to get approximations for energy measurements.\n\n## Installation\n\nTo install pytest energy reporter, simply run:\n\n```bash\npip install pytest_energy_reporter\n```\n\n## Usage\n\nThe package is automatically enabled in pytest. If it is not, make sure to read the documentation on [how to enable plugins in pytest](https://docs.pytest.org/en/stable/how-to/plugins.html). To start measuring energy consumption, mark tests as energy test using:\n\n```python\nimport pytest\n\n@pytest.mark.energy\ndef test_fn():\n\n# Or define the exact number of iterations to measure\n@pytest.mark.energy(n=3)\ndef test_fn():\n\n# Or use the measurement directly\nfrom pytest_energy_reporter.measurement import measure_energy\n\ndef test_fn():\n  measure = measure_energy(fn)\n  assert measure.energy_j < 200\n\n# Or use the measurement and the result of the method\nfrom pytest_energy_reporter.measurement import measure\n\ndef test_fn():\n  measure, result, error = measure(fn, n=2)\n  assert result == # ...\n  assert error == None\n  assert result.energy_j < 200\n```\n\nThe plugin exposes a few flags in pytest\n\n| Flag | Argument | Default | Meaning |\n| --- | --- | --- | --- |\n| `--energy-iterations` | `int` | `3` |  Specify the number of iterations for the energy measurement. |\n| `--save-energy-report` | `<none>` | `False` | Feature flag to save the energy report.\n| `--energy-report-path` | `str` | `'reports/energy'` | The path to save the energy report in.\n| `--energy-offset-zero` | `<none>` | `False` | Feature flag to compensate the power measurement by the power draw of zero utilization.\n\n## Contributing\n\n### Prerequistes\n\nMake sure you have [poetry](https://python-poetry.org/) installed.\n\n### Installation\n\nTo install the pytest energy reporter repository, run:\n\n1. Clone the repository\n```bash\ngit clone git@github.com:delanoflipse/pytest-energy-reporter.git\n```\n\n2. Install dependencies \n```bash\npoetry install\n```\n### Usage\n\nTo develop the plugin, use:\n\n```bash\npoetry shell\n```\n\nAnd run the example test suite:\n\n```bash\npytest --log-cli-level=DEBUG\n```\n\n### Publishing\n\n1. Build the project:\n\n```bash\npoetry build\n```\n2. Publish to pip (make sure you [have credentials setup](https://python-poetry.org/docs/repositories/#configuring-credentials)):\n```bash\npoetry publish\n```",
    "bugtrack_url": null,
    "license": "license.txt",
    "summary": "An energy estimation reporter for pytest",
    "version": "0.5.2",
    "project_urls": {
        "Bug Tracker": "https://github.com/delanoflipse/pytest-energy-reporter/issues",
        "Documentation": "https://github.com/delanoflipse/pytest-energy-reporter",
        "Homepage": "https://github.com/delanoflipse/pytest-energy-reporter",
        "Repository": "https://github.com/delanoflipse/pytest-energy-reporter"
    },
    "split_keywords": [
        "pytest",
        " energy",
        " reporter"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b74815494a3a70683965fd5a844c062ebc793fb2949efa5e4151ee11ee9f9b87",
                "md5": "1972e0bf5cff339617b87610397c9040",
                "sha256": "0726524fd8b40e1f80bf5ffd19de40756ced13a0888bbf1b5476c00a14cdcd8e"
            },
            "downloads": -1,
            "filename": "pytest_energy_reporter-0.5.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1972e0bf5cff339617b87610397c9040",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.10",
            "size": 19807,
            "upload_time": "2024-03-28T22:35:24",
            "upload_time_iso_8601": "2024-03-28T22:35:24.643713Z",
            "url": "https://files.pythonhosted.org/packages/b7/48/15494a3a70683965fd5a844c062ebc793fb2949efa5e4151ee11ee9f9b87/pytest_energy_reporter-0.5.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ac08f403e403a05803356a3e97b6d91d3d0259fb3704615fbaf321d59cfd83ba",
                "md5": "35ced7ce313693ea887dba028eed13c9",
                "sha256": "e3515d81ca067103f7766b622de47f737a85de94fb308f16a973c8f59a55ed90"
            },
            "downloads": -1,
            "filename": "pytest_energy_reporter-0.5.2.tar.gz",
            "has_sig": false,
            "md5_digest": "35ced7ce313693ea887dba028eed13c9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.10",
            "size": 18320,
            "upload_time": "2024-03-28T22:35:26",
            "upload_time_iso_8601": "2024-03-28T22:35:26.527625Z",
            "url": "https://files.pythonhosted.org/packages/ac/08/f403e403a05803356a3e97b6d91d3d0259fb3704615fbaf321d59cfd83ba/pytest_energy_reporter-0.5.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-28 22:35:26",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "delanoflipse",
    "github_project": "pytest-energy-reporter",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pytest_energy_reporter"
}
        
Elapsed time: 0.21354s