pytest-memray


Namepytest-memray JSON
Version 1.7.0 PyPI version JSON
download
home_pageNone
SummaryA simple plugin to use with pytest
upload_time2024-07-25 13:18:09
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <img src="https://raw.githubusercontent.com/bloomberg/pytest-memray/main/docs/_static/images/logo.png" width="70%" style="display: block; margin: 0 auto"  alt="logo"/>

# pytest-memray

[![PyPI](https://img.shields.io/pypi/v/pytest-memray?style=flat-square)](https://pypi.org/project/pytest-memray)
[![PyPI - Implementation](https://img.shields.io/pypi/implementation/pytest-memray?style=flat-square)](https://pypi.org/project/pytest-memray)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pytest-memray?style=flat-square)](https://pypi.org/project/pytest-memray)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/pytest-memray?style=flat-square)](https://pypistats.org/packages/pytest-memray)
[![PyPI - License](https://img.shields.io/pypi/l/pytest-memray?style=flat-square)](https://opensource.org/licenses/MIT)
[![Tests](https://github.com/bloomberg/pytest-memray/actions/workflows/build.yml/badge.svg)](https://github.com/bloomberg/pytest-memray/actions/workflows/build.yml)
![Code Style](https://img.shields.io/badge/code%20style-black-000000.svg)

pytest-memray is a pytest plugin for easy integration of
[memray](https://github.com/bloomberg/memray).

## Installation

pytest-memray requires Python 3.8 or higher and can be easily installed using most
common Python packaging tools. We recommend installing the latest stable release from
[PyPI](https://pypi.org/project/pytest-memray/) with pip:

```shell
pip install pytest-memray
```

## Documentation

You can find the latest documentation available
[here](https://pytest-memray.readthedocs.io/en/latest/).

## Quick introduction

To use the plugin in a pytest run, simply add `--memray` to the command line invocation:

```shell
pytest --memray tests
```

After the test suite runs you'll see a memory report printed:

```bash
=================================== test session starts ====================================
platform linux -- Python 3.10.4, pytest-7.1.2, pluggy-1.0.0
cachedir: /v/.pytest_cache
rootdir: /w
plugins: memray-1.1.0
collected 2 items

demo/test_ok.py .M                                                                   [100%]

========================================= FAILURES =========================================
____________________________________ test_memory_exceed ____________________________________
Test was limited to 100.0KiB but allocated 117.2KiB
------------------------------------ memray-max-memory -------------------------------------
Test is using 117.2KiB out of limit of 100.0KiB
List of allocations:
	- <listcomp>:/w/demo/test_ok.py:17 -> 117.2KiB

====================================== MEMRAY REPORT =======================================
Allocations results for demo/test_ok.py::test_memory_exceed

	 📦 Total memory allocated: 117.2KiB
	 📏 Total allocations: 30
	 📊 Histogram of allocation sizes: |█|
	 🥇 Biggest allocating functions:
		- <listcomp>:/w/demo/test_ok.py:17 -> 117.2KiB


Allocations results for demo/test_ok.py::test_track

	 📦 Total memory allocated: 54.9KiB
	 📏 Total allocations: 71
	 📊 Histogram of allocation sizes: |█   ▅    |
	 🥇 Biggest allocating functions:
		- test_track:/w/demo/test_ok.py:12 -> 39.1KiB
		- _compile_bytecode:<frozen importlib._bootstrap_external>:672 -> 7.2KiB
		- _call_with_frames_removed:<frozen importlib._bootstrap>:241 -> 4.7KiB
		- _call_with_frames_removed:<frozen importlib._bootstrap>:241 -> 1.8KiB
		- _is_marked_for_rewrite:/v/lib/python3.10/site-packages/_pytest/assertion/rewrite.py:240 -> 1.1KiB


================================= short test summary info ==================================
MEMORY PROBLEMS demo/test_ok.py::test_memory_exceed
=============================== 1 failed, 1 passed in 0.01s ================================
```

## Configuration - CLI flags

- `--memray` - activate memray tracking
- `--most-allocations=MOST_ALLOCATIONS` - show the N tests that allocate most memory
  (N=0 for all)
- `--hide-memray-summary` - hide the memray summary at the end of the execution
- `--memray-bin-path` - path where to write the memray binary dumps (by default a
  temporary folder)
- `--memray-bin-prefix` - prefix to use for the binary dump (by default a random UUID4
  hex)
- `--stacks=STACKS` - Show the N stack entries when showing tracebacks of memory allocations
- `--native` - Show native frames when showing tracebacks of memory allocations (will be slower)
- `--trace-python-allocators` - Record allocations made by the Pymalloc allocator (will be slower)
- `--fail-on-increase` - Fail a test with the `limit_memory`` marker if it uses
  more memory than its last successful run

## Configuration - INI

- `memray(bool)` - activate memray tracking
- `most-allocations(string)` - show the N tests that allocate most memory (N=0 for all)
- `hide_memray_summary(bool)` - hide the memray summary at the end of the execution
- `stacks(int)` - Show the N stack entries when showing tracebacks of memory allocations
- `native(bool)`- Show native frames when showing tracebacks of memory allocations (will be slower)
- `trace_python_allocators(bool)` - Record allocations made by the Pymalloc allocator (will be slower)
- `fail-on-increase(bool)` - Fail a test with the `limit_memory` marker if it
  uses more memory than its last successful run

## License

pytest-memray is Apache-2.0 licensed, as found in the [LICENSE](LICENSE) file.

## Code of Conduct

- [Code of Conduct](https://github.com/bloomberg/.github/blob/main/CODE_OF_CONDUCT.md)

This project has adopted a Code of Conduct. If you have any concerns about the Code, or
behavior which you have experienced in the project, please contact us at
opensource@bloomberg.net.

## Security Policy

- [Security Policy](https://github.com/bloomberg/pytest-memray/security/policy)

If you believe you have identified a security vulnerability in this project, please send
email to the project team at opensource@bloomberg.net, detailing the suspected issue and
any methods you've found to reproduce it.

Please do NOT open an issue in the GitHub repository, as we'd prefer to keep
vulnerability reports private until we've had an opportunity to review and address them.

## Contributing

We welcome your contributions to help us improve and extend this project!

Below you will find some basic steps required to be able to contribute to the project.
If you have any questions about this process or any other aspect of contributing to a
Bloomberg open source project, feel free to email opensource@bloomberg.net, and we'll
get your questions answered as quickly as we can.

### Contribution Licensing

Since this project is distributed under the terms of an [open source license](LICENSE),
contributions that you make are licensed under the same terms. In order for us to be
able to accept your contributions, we will need explicit confirmation from you that you
are able and willing to provide them under these terms, and the mechanism we use to do
this is called a Developer's Certificate of Origin
[(DCO)](https://github.com/bloomberg/.github/blob/main/DCO.md). This is very similar to
the process used by the Linux(R) kernel, Samba, and many other major open source
projects.

To participate under these terms, all that you must do is include a line like the
following as the last line of the commit message for each commit in your contribution:

```git
Signed-Off-By: Random J. Developer <random@developer.example.org>
```

The simplest way to accomplish this is to add `-s` or `--signoff` to your `git commit`
command.

You must use your real name (sorry, no pseudonyms, and no anonymous contributions).

### Steps

- Create an Issue, selecting 'Feature Request', and explain the proposed change.
- Follow the guidelines in the issue template presented to you.
- Submit the Issue.
- Submit a Pull Request and link it to the Issue by including "#<issue number>" in the
  Pull Request summary.

### Development

The project requires a Linux OS to work. To set up a DEV environment use tox (or
directly the make targets). You can use Docker to run the test suite on non Linux as in
(you can parametrize tox by passing additional arguments at the end):

```shell
docker-compose run --rm test tox
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pytest-memray",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "Pablo Galindo Salgado <pgalindo3@bloomberg.net>",
    "keywords": null,
    "author": null,
    "author_email": "Pablo Galindo Salgado <pgalindo3@bloomberg.net>",
    "download_url": "https://files.pythonhosted.org/packages/4b/33/31536fa35fae6b040f7bb31375c6b95d025eb38e16416c23c0daa36bcb1f/pytest_memray-1.7.0.tar.gz",
    "platform": null,
    "description": "<img src=\"https://raw.githubusercontent.com/bloomberg/pytest-memray/main/docs/_static/images/logo.png\" width=\"70%\" style=\"display: block; margin: 0 auto\"  alt=\"logo\"/>\n\n# pytest-memray\n\n[![PyPI](https://img.shields.io/pypi/v/pytest-memray?style=flat-square)](https://pypi.org/project/pytest-memray)\n[![PyPI - Implementation](https://img.shields.io/pypi/implementation/pytest-memray?style=flat-square)](https://pypi.org/project/pytest-memray)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pytest-memray?style=flat-square)](https://pypi.org/project/pytest-memray)\n[![PyPI - Downloads](https://img.shields.io/pypi/dm/pytest-memray?style=flat-square)](https://pypistats.org/packages/pytest-memray)\n[![PyPI - License](https://img.shields.io/pypi/l/pytest-memray?style=flat-square)](https://opensource.org/licenses/MIT)\n[![Tests](https://github.com/bloomberg/pytest-memray/actions/workflows/build.yml/badge.svg)](https://github.com/bloomberg/pytest-memray/actions/workflows/build.yml)\n![Code Style](https://img.shields.io/badge/code%20style-black-000000.svg)\n\npytest-memray is a pytest plugin for easy integration of\n[memray](https://github.com/bloomberg/memray).\n\n## Installation\n\npytest-memray requires Python 3.8 or higher and can be easily installed using most\ncommon Python packaging tools. We recommend installing the latest stable release from\n[PyPI](https://pypi.org/project/pytest-memray/) with pip:\n\n```shell\npip install pytest-memray\n```\n\n## Documentation\n\nYou can find the latest documentation available\n[here](https://pytest-memray.readthedocs.io/en/latest/).\n\n## Quick introduction\n\nTo use the plugin in a pytest run, simply add `--memray` to the command line invocation:\n\n```shell\npytest --memray tests\n```\n\nAfter the test suite runs you'll see a memory report printed:\n\n```bash\n=================================== test session starts ====================================\nplatform linux -- Python 3.10.4, pytest-7.1.2, pluggy-1.0.0\ncachedir: /v/.pytest_cache\nrootdir: /w\nplugins: memray-1.1.0\ncollected 2 items\n\ndemo/test_ok.py .M                                                                   [100%]\n\n========================================= FAILURES =========================================\n____________________________________ test_memory_exceed ____________________________________\nTest was limited to 100.0KiB but allocated 117.2KiB\n------------------------------------ memray-max-memory -------------------------------------\nTest is using 117.2KiB out of limit of 100.0KiB\nList of allocations:\n\t- <listcomp>:/w/demo/test_ok.py:17 -> 117.2KiB\n\n====================================== MEMRAY REPORT =======================================\nAllocations results for demo/test_ok.py::test_memory_exceed\n\n\t \ud83d\udce6 Total memory allocated: 117.2KiB\n\t \ud83d\udccf Total allocations: 30\n\t \ud83d\udcca Histogram of allocation sizes: |\u2588|\n\t \ud83e\udd47 Biggest allocating functions:\n\t\t- <listcomp>:/w/demo/test_ok.py:17 -> 117.2KiB\n\n\nAllocations results for demo/test_ok.py::test_track\n\n\t \ud83d\udce6 Total memory allocated: 54.9KiB\n\t \ud83d\udccf Total allocations: 71\n\t \ud83d\udcca Histogram of allocation sizes: |\u2588   \u2585    |\n\t \ud83e\udd47 Biggest allocating functions:\n\t\t- test_track:/w/demo/test_ok.py:12 -> 39.1KiB\n\t\t- _compile_bytecode:<frozen importlib._bootstrap_external>:672 -> 7.2KiB\n\t\t- _call_with_frames_removed:<frozen importlib._bootstrap>:241 -> 4.7KiB\n\t\t- _call_with_frames_removed:<frozen importlib._bootstrap>:241 -> 1.8KiB\n\t\t- _is_marked_for_rewrite:/v/lib/python3.10/site-packages/_pytest/assertion/rewrite.py:240 -> 1.1KiB\n\n\n================================= short test summary info ==================================\nMEMORY PROBLEMS demo/test_ok.py::test_memory_exceed\n=============================== 1 failed, 1 passed in 0.01s ================================\n```\n\n## Configuration - CLI flags\n\n- `--memray` - activate memray tracking\n- `--most-allocations=MOST_ALLOCATIONS` - show the N tests that allocate most memory\n  (N=0 for all)\n- `--hide-memray-summary` - hide the memray summary at the end of the execution\n- `--memray-bin-path` - path where to write the memray binary dumps (by default a\n  temporary folder)\n- `--memray-bin-prefix` - prefix to use for the binary dump (by default a random UUID4\n  hex)\n- `--stacks=STACKS` - Show the N stack entries when showing tracebacks of memory allocations\n- `--native` - Show native frames when showing tracebacks of memory allocations (will be slower)\n- `--trace-python-allocators` - Record allocations made by the Pymalloc allocator (will be slower)\n- `--fail-on-increase` - Fail a test with the `limit_memory`` marker if it uses\n  more memory than its last successful run\n\n## Configuration - INI\n\n- `memray(bool)` - activate memray tracking\n- `most-allocations(string)` - show the N tests that allocate most memory (N=0 for all)\n- `hide_memray_summary(bool)` - hide the memray summary at the end of the execution\n- `stacks(int)` - Show the N stack entries when showing tracebacks of memory allocations\n- `native(bool)`- Show native frames when showing tracebacks of memory allocations (will be slower)\n- `trace_python_allocators(bool)` - Record allocations made by the Pymalloc allocator (will be slower)\n- `fail-on-increase(bool)` - Fail a test with the `limit_memory` marker if it\n  uses more memory than its last successful run\n\n## License\n\npytest-memray is Apache-2.0 licensed, as found in the [LICENSE](LICENSE) file.\n\n## Code of Conduct\n\n- [Code of Conduct](https://github.com/bloomberg/.github/blob/main/CODE_OF_CONDUCT.md)\n\nThis project has adopted a Code of Conduct. If you have any concerns about the Code, or\nbehavior which you have experienced in the project, please contact us at\nopensource@bloomberg.net.\n\n## Security Policy\n\n- [Security Policy](https://github.com/bloomberg/pytest-memray/security/policy)\n\nIf you believe you have identified a security vulnerability in this project, please send\nemail to the project team at opensource@bloomberg.net, detailing the suspected issue and\nany methods you've found to reproduce it.\n\nPlease do NOT open an issue in the GitHub repository, as we'd prefer to keep\nvulnerability reports private until we've had an opportunity to review and address them.\n\n## Contributing\n\nWe welcome your contributions to help us improve and extend this project!\n\nBelow you will find some basic steps required to be able to contribute to the project.\nIf you have any questions about this process or any other aspect of contributing to a\nBloomberg open source project, feel free to email opensource@bloomberg.net, and we'll\nget your questions answered as quickly as we can.\n\n### Contribution Licensing\n\nSince this project is distributed under the terms of an [open source license](LICENSE),\ncontributions that you make are licensed under the same terms. In order for us to be\nable to accept your contributions, we will need explicit confirmation from you that you\nare able and willing to provide them under these terms, and the mechanism we use to do\nthis is called a Developer's Certificate of Origin\n[(DCO)](https://github.com/bloomberg/.github/blob/main/DCO.md). This is very similar to\nthe process used by the Linux(R) kernel, Samba, and many other major open source\nprojects.\n\nTo participate under these terms, all that you must do is include a line like the\nfollowing as the last line of the commit message for each commit in your contribution:\n\n```git\nSigned-Off-By: Random J. Developer <random@developer.example.org>\n```\n\nThe simplest way to accomplish this is to add `-s` or `--signoff` to your `git commit`\ncommand.\n\nYou must use your real name (sorry, no pseudonyms, and no anonymous contributions).\n\n### Steps\n\n- Create an Issue, selecting 'Feature Request', and explain the proposed change.\n- Follow the guidelines in the issue template presented to you.\n- Submit the Issue.\n- Submit a Pull Request and link it to the Issue by including \"#<issue number>\" in the\n  Pull Request summary.\n\n### Development\n\nThe project requires a Linux OS to work. To set up a DEV environment use tox (or\ndirectly the make targets). You can use Docker to run the test suite on non Linux as in\n(you can parametrize tox by passing additional arguments at the end):\n\n```shell\ndocker-compose run --rm test tox\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A simple plugin to use with pytest",
    "version": "1.7.0",
    "project_urls": {
        "Bug Tracker": "https://github.com/bloomberg/pytest-memray/issues",
        "Documentation": "https://pytest-memray.readthedocs.io",
        "Source Code": "https://github.com/bloomberg/pytest-memray"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "241bfe19affdc41e522aabc4e5df78edb0cd8f59cb6ae2fb151dec1797593a42",
                "md5": "0c02596f201d3442215312ef32281f26",
                "sha256": "b896718c1adf6d0cd339dfaaaa5620f035c9919e1199a79b3453804a1254306f"
            },
            "downloads": -1,
            "filename": "pytest_memray-1.7.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0c02596f201d3442215312ef32281f26",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 17679,
            "upload_time": "2024-07-25T13:18:07",
            "upload_time_iso_8601": "2024-07-25T13:18:07.482496Z",
            "url": "https://files.pythonhosted.org/packages/24/1b/fe19affdc41e522aabc4e5df78edb0cd8f59cb6ae2fb151dec1797593a42/pytest_memray-1.7.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4b3331536fa35fae6b040f7bb31375c6b95d025eb38e16416c23c0daa36bcb1f",
                "md5": "f29b4ca14c94769c3cd407d8d39c1621",
                "sha256": "c18fa907d2210b42f4096c093e2d3416dfc002dcaa450ef3f9ba819bc3dd8f5f"
            },
            "downloads": -1,
            "filename": "pytest_memray-1.7.0.tar.gz",
            "has_sig": false,
            "md5_digest": "f29b4ca14c94769c3cd407d8d39c1621",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 240564,
            "upload_time": "2024-07-25T13:18:09",
            "upload_time_iso_8601": "2024-07-25T13:18:09.081252Z",
            "url": "https://files.pythonhosted.org/packages/4b/33/31536fa35fae6b040f7bb31375c6b95d025eb38e16416c23c0daa36bcb1f/pytest_memray-1.7.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-25 13:18:09",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "bloomberg",
    "github_project": "pytest-memray",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "pytest-memray"
}
        
Elapsed time: 0.27826s