Skip to content

Commit

Permalink
- r isolate copied code
Browse files Browse the repository at this point in the history
  • Loading branch information
isidore committed Jan 28, 2024
1 parent dc9804b commit 33df80f
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions approvaltests/namer/stack_frame_namer.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ def get_test_frame_index(caller: List[FrameInfo]) -> int:
def is_pytest_test(frame: FrameInfo) -> bool:
method_name = frame[3]
patterns = PytestConfig.test_naming_patterns

return StackFrameNamer._is_match_for_pytest(method_name, patterns)
@staticmethod
def _is_match_for_pytest(method_name: str, patterns: List[str]) -> bool:
# Do not modify this method, so we can compare with original code
# taken from pytest/python.py (class PyCollector)
for pattern in patterns:
if method_name.startswith(pattern):
Expand All @@ -54,12 +57,12 @@ def is_pytest_test(frame: FrameInfo) -> bool:
# because this is called for every name in each collected module,
# and fnmatch is somewhat expensive to call.
elif (
"*" in pattern or "?" in pattern or "[" in pattern
"*" in pattern or "?" in pattern or "[" in pattern
) and fnmatch.fnmatch(method_name, pattern):
return True

return False

@staticmethod
def is_unittest_test(frame: FrameInfo) -> bool:
method_name = frame[3]
Expand Down Expand Up @@ -107,3 +110,5 @@ def get_test_frame(cls) -> FrameInfo:
calling_stack = inspect.stack(1)
frame = StackFrameNamer.get_test_frame_index(calling_stack)
return calling_stack[frame]


0 comments on commit 33df80f

Please sign in to comment.