- Notifications
You must be signed in to change notification settings - Fork26
pytest plugin for easy integration of memray memory profiler
License
bloomberg/pytest-memray
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
pytest-memray is a pytest plugin for easy integration ofmemray.
pytest-memray requires Python 3.8 or higher and can be easily installed using mostcommon Python packaging tools. We recommend installing the latest stable release fromPyPI with pip:
pip install pytest-memray
You can find the latest documentation availablehere.
To use the plugin in a pytest run, simply add--memray
to the command line invocation:
pytest --memray tests
After the test suite runs you'll see a memory report printed:
===================================test session starts ====================================platform linux -- Python 3.10.4, pytest-7.1.2, pluggy-1.0.0cachedir: /v/.pytest_cacherootdir: /wplugins: memray-1.1.0collected 2 itemsdemo/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.0KiBList of allocations:-<listcomp>:/w/demo/test_ok.py:17 -> 117.2KiB====================================== MEMRAY REPORT =======================================Allocations resultsfor 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.2KiBAllocations resultsfor 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================================= shorttest summary info ==================================MEMORY PROBLEMS demo/test_ok.py::test_memory_exceed=============================== 1 failed, 1 passedin 0.01s ================================
--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 atemporary folder)--memray-bin-prefix
- prefix to use for the binary dump (by default a random UUID4hex)--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 usesmore memory than its last successful run
memray(bool)
- activate memray trackingmost-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 executionstacks(int)
- Show the N stack entries when showing tracebacks of memory allocationsnative(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 thelimit_memory
marker if ituses more memory than its last successful run
pytest-memray is Apache-2.0 licensed, as found in theLICENSE file.
This project has adopted a Code of Conduct. If you have any concerns about the Code, orbehavior which you have experienced in the project, please contact us atopensource@bloomberg.net.
If you believe you have identified a security vulnerability in this project, please sendemail to the project team atopensource@bloomberg.net, detailing the suspected issue andany methods you've found to reproduce it.
Please do NOT open an issue in the GitHub repository, as we'd prefer to keepvulnerability reports private until we've had an opportunity to review and address them.
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 aBloomberg open source project, feel free to emailopensource@bloomberg.net, and we'llget your questions answered as quickly as we can.
Since this project is distributed under the terms of anopen source license,contributions that you make are licensed under the same terms. In order for us to beable to accept your contributions, we will need explicit confirmation from you that youare able and willing to provide them under these terms, and the mechanism we use to dothis is called a Developer's Certificate of Origin(DCO). This is very similar tothe process used by the Linux(R) kernel, Samba, and many other major open sourceprojects.
To participate under these terms, all that you must do is include a line like thefollowing as the last line of the commit message for each commit in your contribution:
Signed-Off-By: Random J. Developer <random@developer.example.org>
The simplest way to accomplish this is to add-s
or--signoff
to yourgit commit
command.
You must use your real name (sorry, no pseudonyms, and no anonymous contributions).
- 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 "#" in thePull Request summary.
The project requires a Linux OS to work. To set up a DEV environment use tox (ordirectly 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):
docker-compose run --rmtest tox
About
pytest plugin for easy integration of memray memory profiler