Skip to content

Memory leak when running pytest on macOS #13636

@janbridley

Description

@janbridley

Description

Running pytest on macOS (both for the Pytest library itself as well as a few other libraries) leaks a small amount of memory.

Steps to reproduce

> git clone https://github.com/pytest-dev/pytest.git
> pip install .
> sudo leaks --atExit -- python -m pytest | grep bytes

Process 95884: 3 leaks for 4656 total leaked bytes.
    1 (560 bytes) ROOT LEAK: <malloc in _PyObject_Malloc 0x105d5ad10> [560]

When running pytest on other projects, I get a leak of a different size and a different source: but it only occurs when running pytest. Importing the package and calling functions from it does not leak any memory.

> sudo leaks --atExit -- python -m pytest <my_libraries> | grep bytes
   1 (16 bytes) ROOT LEAK: <non-object from libedit.3.dylib 0x127092d20> [16]

pip list

> pip list
Package            Version
------------------ ----------------------
argcomplete        3.6.2
attrs              25.3.0
certifi            2025.8.3
charset-normalizer 3.4.2
elementpath        5.0.3
hypothesis         6.137.1
idna               3.10
iniconfig          2.1.0
mock               5.2.0
packaging          25.0
pip                25.2
pluggy             1.6.0
Pygments           2.19.2
pytest             8.5.0.dev66+g5989efe3e
requests           2.32.4
setuptools         80.9.0
sortedcontainers   2.4.0
urllib3            2.5.0
xmlschema          4.1.0

I reproduced this behavior in a uv environment, and in a micromamba environment where I installed pip.

> pytest --version
pytest 8.4.1 # Built from source
> python --version
Python 3.15.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: needs informationreporter needs to provide more information; can be closed after 2 or more weeks of inactivity

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions