Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Matt Wozniski <[email protected]>
  • Loading branch information
pablogsal and godlygeek committed Apr 18, 2024
1 parent 3631eed commit f06157b
Showing 1 changed file with 12 additions and 22 deletions.
34 changes: 12 additions & 22 deletions src/pytest_memray/marks.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,20 +193,13 @@ def limit_memory(
) -> _MemoryInfo | _MoreMemoryInfo | None:
"""Limit memory used by the test."""
reader = FileReader(_result_file)
allocations: list[AllocationRecord] = []
if current_thread_only:
main_thread = reader.metadata.main_thread_id
allocations.extend(
record
for record in reader.get_high_watermark_allocation_records(
merge_threads=False
)
if record.tid == main_thread
)
else:
allocations.extend(
reader.get_high_watermark_allocation_records(merge_threads=True)
allocations: list[AllocationRecord] = [
record
for record in reader.get_high_watermark_allocation_records(
merge_threads=not current_thread_only
)
if not current_thread_only or record.tid == reader.metadata.main_thread_id
]
max_memory = parse_memory_string(limit)
total_allocated_memory = sum(record.size for record in allocations)

Expand Down Expand Up @@ -243,16 +236,13 @@ def limit_leaks(
_test_id: str,
) -> _LeakedInfo | None:
reader = FileReader(_result_file)
allocations: list[AllocationRecord] = []
if current_thread_only:
main_thread_id = reader.metadata.main_thread_id
allocations.extend(
record
for record in reader.get_leaked_allocation_records(merge_threads=False)
if record.tid == main_thread_id
allocations: list[AllocationRecord] = [
record
for record in reader.get_leaked_allocation_records(
merge_threads=not current_thread_only
)
else:
allocations.extend(reader.get_leaked_allocation_records(merge_threads=True))
if not current_thread_only or record.tid == reader.metadata.main_thread_id
]

memory_limit = parse_memory_string(location_limit)

Expand Down

0 comments on commit f06157b

Please sign in to comment.