Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

pytest-memlog

Continuously logs the memory usage of your test session.

Memlog graph of the example tests

Installation

pip install pytest-memlog

Usage

Use --memlog to enable the plugin.

By default, memory usage of a test run will be logged to memlog.json.

Options

  • --memlog-path: The path to save the log to, defaults to memlog.json.
  • --memlog-interval: Measurement interval, defaults to 0.1 seconds.
  • --memlog-warmup: Memlog will capture memory usage for this many seconds before starting your tests. Defaults to 0.

Markers

  • limit_memory(memory): Will mark a test as failed if the program memory exceeds this number during a test run. Note that due to garbage collection, this does not necessarily reflect memory usage in a specific test.

Implementation

pytest-memlog uses a separate process to track the memory of the test process. This allows for a very low overhead, as the only data passed between the processes are test names & the maximum memory usage during a test.

The memory logging is done at fixed intervals (given by --memlog-interval) and saved to a JSON log. Each log entry is of the following form:

    {
        "rss": 40939520,
        "time": 1814626.921,
        "name": "tests/test_basic.py::test_0"
    }
  • rss is the used memory, in bytes.
  • time is the value from time.monotonic(). You'll probably want to normalize this when analyzing.
  • name is the name of the current running test, or an empty string between tests.

Analysis

The visualization at the top was generated using the data from our examples.

You can see how in the sample notebook or view it live.

To generate the log for the examples run:

pytest --memlog ./examples/

Or use it on your own tests!

Metadata

Release files for pytest-memlog 0.1.0a1

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-memlog 0.1.0a1
File Size Uploaded
pytest_memlog-0.1.0a1.tar.gz 5.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-memlog 0.1.0a1
File Interpreter ABI Platform
pytest_memlog-0.1.0a1-py3-none-any.whl Python 3 none any Details

Total release size: 12.7 kB

Release files / pytest_memlog-0.1.0a1.tar.gz

Download URL pytest_memlog-0.1.0a1.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
40f835763a08d8edb9b1745fbc4cb09f012ab29217da89f6f83a74d348bfba10
BLAKE2b-256 checksum
How to use checksums
18048c2b72e9e1b22d875768f7de5178378ddc879e5c1d879fc147bbdaa5c2d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.1 CPython/3.11.3

Release files / pytest_memlog-0.1.0a1-py3-none-any.whl

Download URL pytest_memlog-0.1.0a1-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f66dfa142d67ea7357bdb44b1ff30bfe56d5966456f890ae6189052f4da772bd
BLAKE2b-256 checksum
How to use checksums
24fff662dda26f2f6bfc7dd50d03a6abee02ae2ec028aa495e862ac7c637c0c9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.1 CPython/3.11.3

Release history Release notifications | RSS feed

This release

0.1.0a1 This release

2 release files

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