Skip to content

Commit 4e5981a

Browse files
committed
Refactor generate_test_name from method to function
1 parent 48e652f commit 4e5981a

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

pytest_mpl/plugin.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,17 @@ def _pytest_pyfunc_call(obj, pyfuncitem):
8989
return True
9090

9191

92+
def generate_test_name(item):
93+
"""
94+
Generate a unique name for the hash for this test.
95+
"""
96+
if item.cls is not None:
97+
name = f"{item.module.__name__}.{item.cls.__name__}.{item.name}"
98+
else:
99+
name = f"{item.module.__name__}.{item.name}"
100+
return name
101+
102+
92103
def pytest_report_header(config, startdir):
93104
import matplotlib
94105
import matplotlib.ft2font
@@ -287,7 +298,7 @@ def generate_filename(self, item):
287298
Given a pytest item, generate the figure filename.
288299
"""
289300
if self.config.getini('mpl-use-full-test-name'):
290-
filename = self.generate_test_name(item) + '.png'
301+
filename = generate_test_name(item) + '.png'
291302
else:
292303
compare = get_compare(item)
293304
# Find test name to use as plot name
@@ -298,21 +309,11 @@ def generate_filename(self, item):
298309
filename = str(pathify(filename))
299310
return filename
300311

301-
def generate_test_name(self, item):
302-
"""
303-
Generate a unique name for the hash for this test.
304-
"""
305-
if item.cls is not None:
306-
name = f"{item.module.__name__}.{item.cls.__name__}.{item.name}"
307-
else:
308-
name = f"{item.module.__name__}.{item.name}"
309-
return name
310-
311312
def make_test_results_dir(self, item):
312313
"""
313314
Generate the directory to put the results in.
314315
"""
315-
test_name = pathify(self.generate_test_name(item))
316+
test_name = pathify(generate_test_name(item))
316317
results_dir = self.results_dir / test_name
317318
results_dir.mkdir(exist_ok=True, parents=True)
318319
return results_dir
@@ -526,7 +527,7 @@ def compare_image_to_hash_library(self, item, fig, result_dir, summary=None):
526527
pytest.fail(f"Can't find hash library at path {hash_library_filename}")
527528

528529
hash_library = self.load_hash_library(hash_library_filename)
529-
hash_name = self.generate_test_name(item)
530+
hash_name = generate_test_name(item)
530531
baseline_hash = hash_library.get(hash_name, None)
531532
summary['baseline_hash'] = baseline_hash
532533

@@ -613,7 +614,7 @@ def pytest_runtest_call(self, item): # noqa
613614
if remove_text:
614615
remove_ticks_and_titles(fig)
615616

616-
test_name = self.generate_test_name(item)
617+
test_name = generate_test_name(item)
617618
result_dir = self.make_test_results_dir(item)
618619

619620
summary = {

0 commit comments

Comments
 (0)