Skip to content

Commit

Permalink
Do not return our result from the pytest_pyfunc_call wrapper (#61)
Browse files Browse the repository at this point in the history
Closes #60
  • Loading branch information
pablogsal committed Dec 2, 2022
1 parent f169899 commit 5c49e7c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/news/60.bugfix.rst
@@ -0,0 +1 @@
Fix pytest raising ``pytest.PytestReturnNotNoneWarning`` from test decorated with memray markers.
5 changes: 3 additions & 2 deletions src/pytest_memray/plugin.py
Expand Up @@ -150,10 +150,11 @@ def _build_bin_path() -> Path:

@functools.wraps(func)
def wrapper(*args: Any, **kwargs: Any) -> object | None:
test_result: object | Any = None
try:
result_file = _build_bin_path()
with Tracker(result_file, native_traces=native):
result: object | None = func(*args, **kwargs)
test_result = func(*args, **kwargs)
try:
metadata = FileReader(result_file).metadata
except OSError:
Expand All @@ -172,7 +173,7 @@ def wrapper(*args: Any, **kwargs: Any) -> object | None:
# hook again with whatever is here, which will cause the wrapper
# to be wrapped again.
pyfuncitem.obj = func
return result
return test_result

pyfuncitem.obj = wrapper
yield
Expand Down
17 changes: 17 additions & 0 deletions tests/test_pytest_memray.py
Expand Up @@ -532,3 +532,20 @@ def test_memory_alloc_fails_2():

result = pytester.runpytest("--memray", "-n", "2")
assert result.ret == outcome


def test_memray_does_not_raise_warnings(pytester: Pytester) -> None:
pytester.makepyfile(
"""
import pytest
from memray._test import MemoryAllocator
allocator = MemoryAllocator()
@pytest.mark.limit_memory("1MB")
def test_memory_alloc_fails():
allocator.valloc(1234)
allocator.free()
"""
)
result = pytester.runpytest("-Werror", "--memray")
assert result.ret == ExitCode.OK

0 comments on commit 5c49e7c

Please sign in to comment.