Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop # type: ignore comments for @hookimpl #95

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
pull_request:
branches:
- main
schedule:
# At 12:00 UTC on every day-of-month
- cron: "0 12 */1 * *"

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
types:
- published
schedule:
# At 12:00 on every day-of-month
# At 12:00 UTC on every day-of-month
- cron: "0 12 */1 * *"

concurrency:
Expand Down
10 changes: 5 additions & 5 deletions src/pytest_memray/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,15 @@ def __init__(self, config: Config) -> None:
self.result_metadata_path = self.result_path / "metadata"
self.result_metadata_path.mkdir(exist_ok=True, parents=True)

@hookimpl(hookwrapper=True) # type: ignore[misc] # Untyped decorator
@hookimpl(hookwrapper=True)
def pytest_unconfigure(self, config: Config) -> Generator[None, None, None]:
yield
if self._tmp_dir is not None:
self._tmp_dir.cleanup()
if os.environ.get("MEMRAY_RESULT_PATH"):
del os.environ["MEMRAY_RESULT_PATH"]

@hookimpl(hookwrapper=True) # type: ignore[misc] # Untyped decorator
@hookimpl(hookwrapper=True)
def pytest_pyfunc_call(self, pyfuncitem: Function) -> object | None:
func = pyfuncitem.obj

Expand Down Expand Up @@ -212,7 +212,7 @@ def wrapper(*args: Any, **kwargs: Any) -> object | None:
pyfuncitem.obj = wrapper
yield

@hookimpl(hookwrapper=True) # type: ignore[misc] # Untyped decorator
@hookimpl(hookwrapper=True)
def pytest_runtest_makereport(
self, item: Item, call: CallInfo[None]
) -> Generator[None, TestReport | None, TestReport | None]:
Expand Down Expand Up @@ -245,7 +245,7 @@ def pytest_runtest_makereport(
outcome.force_result(report)
return None

@hookimpl(hookwrapper=True, trylast=True) # type: ignore[misc] # Untyped decorator
@hookimpl(hookwrapper=True, trylast=True)
def pytest_report_teststatus(
self, report: CollectReport | TestReport
) -> Generator[None, TestReport, None]:
Expand All @@ -257,7 +257,7 @@ def pytest_report_teststatus(
outcome.force_result(("failed", "M", "MEMORY PROBLEMS"))
return None

@hookimpl # type: ignore[misc] # Untyped decorator
@hookimpl
def pytest_terminal_summary(
self, terminalreporter: TerminalReporter, exitstatus: ExitCode
) -> None:
Expand Down
33 changes: 27 additions & 6 deletions tests/test_pytest_memray.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import re
import xml.etree.ElementTree as ET
from types import SimpleNamespace
from unittest.mock import ANY
Expand All @@ -10,6 +11,25 @@
from pytest import ExitCode
from pytest import Pytester

from pytest_memray.marks import StackFrame


def extract_stacks(test_output: str) -> list[list[StackFrame]]:
ret: list[list[StackFrame]] = []
before_start = True
for line in test_output.splitlines():
if before_start:
if "List of allocations:" in line:
before_start = False
elif "allocated here" in line:
ret.append([])
elif (match := re.match(r"^ {8}([^:]+):(.*):(\d+)$", line)) is not None:
ret[-1].append(
StackFrame(function=match[1], filename=match[2], lineno=int(match[3]))
)

return ret


def test_help_message(pytester: Pytester) -> None:
result = pytester.runpytest("--help")
Expand Down Expand Up @@ -176,10 +196,11 @@ def test_foo():

assert result.ret == ExitCode.TESTS_FAILED

output = result.stdout.str()

assert "valloc:" in output
assert output.count("rec:") == min(num_stacks - 1, 10)
stacks = extract_stacks(result.stdout.str())
valloc_stacks = [stack for stack in stacks if stack[0].function == "valloc"]
(valloc_stack,) = valloc_stacks
num_rec_frames = sum(1 for frame in valloc_stack if frame.function == "rec")
assert num_rec_frames == min(num_stacks - 1, 10)


@pytest.mark.parametrize("native", [True, False])
Expand Down Expand Up @@ -348,11 +369,11 @@ def test_memray_report_limit(pytester: Pytester) -> None:
allocator = MemoryAllocator()

def allocating_func1():
allocator.valloc(1024)
allocator.valloc(1024*1024)
allocator.free()

def allocating_func2():
allocator.valloc(1024*2)
allocator.valloc(1024*1024*2)
allocator.free()

def test_foo():
Expand Down