Skip to content

Commit

Permalink
'Refactored by Sourcery'
Browse files Browse the repository at this point in the history
  • Loading branch information
Sourcery AI committed Jan 9, 2024
1 parent 5a10e79 commit 596ddd2
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions approvaltests/namer/stack_frame_namer.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ def set_for_stack(self, caller: List[FrameInfo]) -> None:

@staticmethod
def get_test_frame_index(caller: List[FrameInfo]) -> int:
tmp_array = []
for index, frame in enumerate(caller):
if StackFrameNamer.is_test_method(frame):
tmp_array.append(index)
if tmp_array:
if tmp_array := [
index
for index, frame in enumerate(caller)
if StackFrameNamer.is_test_method(frame)
]:
return tmp_array[-1]
message = """Could not find test method/function. Possible reasons could be:
1) approvaltests is not being used inside a test function
Expand Down Expand Up @@ -63,15 +63,14 @@ def is_pytest_test(method_name: str) -> bool:
def is_unittest_test(frame: FrameInfo) -> bool:
method_name = frame[3]
local_attributes = frame[0].f_locals
is_unittest_test = (
return (
"self" in local_attributes
and hasattr(local_attributes["self"], "__dict__")
and "_testMethodName" in vars(local_attributes["self"])
and method_name != "__call__"
and method_name != "_callTestMethod"
and method_name != "run"
)
return is_unittest_test

@staticmethod
def is_test_method(frame: FrameInfo) -> bool:
Expand All @@ -94,7 +93,7 @@ def config_directory(self) -> str:
return self.directory

def get_file_name(self) -> str:
class_name = "" if (self.class_name is None) else (self.class_name + ".")
class_name = "" if self.class_name is None else f"{self.class_name}."
return class_name + self.method_name

def get_extension_with_dot(self) -> str:
Expand Down

0 comments on commit 596ddd2

Please sign in to comment.