-
Notifications
You must be signed in to change notification settings - Fork 27
Description
Bug Report
Under certain circumstances the generated filename for .bin files can exceed OS limitations on Mac systems. This is more likely in projects with nested folders in their tests (i.e. tests > unit > some_module > test_x.py) or where parametrised tests are being used.
When using parameterised tests pytest will display the values in the test summary, i.e. for an input of:
@pytest.mark.parametrize(
("some_input", "some_expected_value"),
[(1, "A string"), (2, f"A very l{'o' * 200}ng string")],
)
def test_reproduction(some_input: int, some_expected_value: str) -> None:
passran with pytest test_reproduction.py -svv, the following output can be expected:
========================================================================================================== test session starts ===========================================================================================================
platform darwin -- Python 3.13.3, pytest-8.3.5, pluggy-1.6.0 -- /Users/lachlankidson/repos/memray-repro/.venv/bin/python
cachedir: .pytest_cache
rootdir: /Users/lachlankidson/repos/memray-repro
configfile: pyproject.toml
plugins: memray-1.7.0
collected 2 items
test_reproduction.py::test_reproduction[1-A string] PASSED
test_reproduction.py::test_reproduction[2-A very loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong string] PASSED
=========================================================================================================== 2 passed in 0.02s ============================================================================================================
This example works under some configurations of memray, but fails with an OSError if --memray-bin-path is specified due to limitations on filename length, e.g. pytest --memray --memray-bin-path memray test_reproduction.py -svv produces:
================================================================================================================ FAILURES ================================================================================================================
_ test_reproduction[2-A very loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong string] _
args = ()
kwargs = {'some_expected_value': 'A very looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo...ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong string', 'some_input': 2}
@functools.wraps(func)
def wrapper(*args: Any, **kwargs: Any) -> Any:
> with memory_reporting():
.venv/lib/python3.13/site-packages/pytest_memray/plugin.py:213:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../.local/share/uv/python/cpython-3.13.3-macos-aarch64-none/lib/python3.13/contextlib.py:141: in __enter__
return next(self.gen)
.venv/lib/python3.13/site-packages/pytest_memray/plugin.py:190: in memory_reporting
result_file = _build_bin_path()
.venv/lib/python3.13/site-packages/pytest_memray/plugin.py:170: in _build_bin_path
if self._tmp_dir is None and result_file.exists():
../../.local/share/uv/python/cpython-3.13.3-macos-aarch64-none/lib/python3.13/pathlib/_abc.py:450: in exists
self.stat(follow_symlinks=follow_symlinks)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = PosixPath('/Users/lachlankidson/repos/memray-repro/memray/f3a29c6eebd84c06a78568a0158b89cb-test_reproduction.py-test_r...ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong string].bin')
def stat(self, *, follow_symlinks=True):
"""
Return the result of the stat() system call on this path, like
os.stat() does.
"""
> return os.stat(self, follow_symlinks=follow_symlinks)
E OSError: [Errno 63] File name too long: '/Users/lachlankidson/repos/memray-repro/memray/f3a29c6eebd84c06a78568a0158b89cb-test_reproduction.py-test_reproduction[2-A very loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong string].bin'
../../.local/share/uv/python/cpython-3.13.3-macos-aarch64-none/lib/python3.13/pathlib/_local.py:515: OSError
============================================================================================================= MEMRAY REPORT ==============================================================================================================
Created 1 binary dumps at /Users/lachlankidson/repos/memray-repro/memray with prefix f3a29c6eebd84c06a78568a0158b89cb
======================================================================================================== short test summary info =========================================================================================================
FAILED test_reproduction.py::test_reproduction[2-A very loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong string] - OSError: [Errno 63] File name too long: '/Users/lachlankidson/repos/memray-repro/memray/f3a29c6eebd84c06a78568a0158b89cb-test_reproduction.py-test_reproduction[2-A very loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong string].bin'
====================================================================================================== 1 failed, 1 passed in 0.28s =======================================================================================================
Expected behavior/code
pytest-memray does not produce filenames that are incompatible with the host operating system.
Environment
- OS: macOS Sequoia 15.4.1
- Python(s): 3.13.3 (via uv / python-build-standalone)
- memray: 1.17.2
- pytest: 8.3.5
- pytest-memray: 1.7.0
Possible Solution
- Check filename length after generation and omit warnings, provide documentation for fixing this issue via pytest configuration, e.g. https://docs.pytest.org/en/stable/example/parametrize.html#set-marks-or-test-id-for-individual-parametrized-test
@pytest.mark.parametrize(
("some_input", "some_expected_value"),
[pytest.param(1, "A string", id="1"), pytest.param(2, f"A very l{'o' * 200}ng string", id="2")],
)
def test_reproduction(some_input: int, some_expected_value: str) -> None:
passOutput:
========================================================================================================== test session starts ===========================================================================================================
platform darwin -- Python 3.13.3, pytest-8.3.5, pluggy-1.6.0 -- /Users/lachlankidson/repos/memray-repro/.venv/bin/python
cachedir: .pytest_cache
rootdir: /Users/lachlankidson/repos/memray-repro
configfile: pyproject.toml
plugins: memray-1.7.0
collected 2 items
test_reproduction.py::test_reproduction[1] PASSED
test_reproduction.py::test_reproduction[2] PASSED
============================================================================================================= MEMRAY REPORT ==============================================================================================================
Created 2 binary dumps at /Users/lachlankidson/repos/memray-repro/memray with prefix 0ab4300122d24f3d958bc923cd41ecb7
=========================================================================================================== 2 passed in 0.07s ============================================================================================================