Skip to content

Commit

Permalink
disable line coverage events for hypothesis files
Browse files Browse the repository at this point in the history
  • Loading branch information
tybug committed Nov 17, 2024
1 parent 01d5d3e commit 96d74dc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
3 changes: 3 additions & 0 deletions hypothesis-python/RELEASE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
RELEASE_TYPE: patch

Hypothesis collects coverage information during the :ref:`shrinking hypothesis.Phase.shrink` and :ref:`explain hypothesis.Phase.explain` phases in order to show a more informative error message. On 3.12+, this uses :mod:`sys.monitoring`. This patch improves the performance of coverage collection on 3.12+ by disabling events we don't need.
11 changes: 6 additions & 5 deletions hypothesis-python/src/hypothesis/internal/scrutineer.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ def trace(self, frame, event, arg):
if event == "call":
return self.trace
elif event == "line":
# manual inlining of self.trace_line for performance.
fname = frame.f_code.co_filename
if should_trace_file(fname):
current_location = (fname, frame.f_lineno)
Expand All @@ -87,10 +86,12 @@ def trace(self, frame, event, arg):

def trace_line(self, code: types.CodeType, line_number: int) -> None:
fname = code.co_filename
if should_trace_file(fname):
current_location = (fname, line_number)
self.branches.add((self._previous_location, current_location))
self._previous_location = current_location
if not should_trace_file(fname):
return sys.monitoring.DISABLE

current_location = (fname, line_number)
self.branches.add((self._previous_location, current_location))
self._previous_location = current_location

def __enter__(self):
if not self._should_trace:
Expand Down

0 comments on commit 96d74dc

Please sign in to comment.