Skip to content

Commit 41cd651

Browse files
committed
html
1 parent 7d2287d commit 41cd651

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

pytest_mpl/plugin.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,10 @@ def pytest_addoption(parser):
147147
group.addoption('--mpl-hash-library',
148148
help="json library of image hashes, relative to "
149149
"location where py.test is run", action='store')
150-
group.addoption('--mpl-generate-summary', action='store_true',
151-
help="Generate a summary HTML report of any failed tests"
152-
", in --mpl-results-path")
150+
group.addoption('--mpl-generate-summary', action='store',
151+
help="Generate a summary report of any failed tests"
152+
", in --mpl-results-path. The type of the report should be "
153+
"specified, the only format supported at the moment is `html`.")
153154

154155
results_path_help = "directory for test results, relative to location where py.test is run"
155156
group.addoption('--mpl-results-path', help=results_path_help, action='store')
@@ -261,7 +262,7 @@ def __init__(self,
261262
results_dir=None,
262263
hash_library=None,
263264
generate_hash_library=None,
264-
generate_summary=False
265+
generate_summary=None
265266
):
266267
self.config = config
267268
self.baseline_dir = baseline_dir
@@ -270,7 +271,9 @@ def __init__(self,
270271
self.results_dir = path_is_not_none(results_dir)
271272
self.hash_library = path_is_not_none(hash_library)
272273
self.generate_hash_library = path_is_not_none(generate_hash_library)
273-
self.generate_summary = bool(generate_summary)
274+
if generate_summary and generate_summary.lower() not in ("html",):
275+
raise ValueError(f"The mpl summary type '{generate_summary}' is not supported.")
276+
self.generate_summary = generate_summary
274277

275278
# Generate the containing dir for all test results
276279
if not self.results_dir:
@@ -611,7 +614,7 @@ def pytest_unconfigure(self, config):
611614
with open(hash_library_path, "w") as fp:
612615
json.dump(self._generated_hash_library, fp, indent=2)
613616

614-
if self.generate_summary:
617+
if self.generate_summary and self.generate_summary.lower() == 'html':
615618
# Generate a list of test directories
616619
dir_list = [p.relative_to(self.results_dir)
617620
for p in self.results_dir.iterdir() if p.is_dir()]

tests/test_pytest_mpl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ def test_hash_fails(tmpdir):
292292
assert "Unable to find baseline image" not in output, output
293293

294294
# Check that the summary path is printed and that it exists.
295-
output = assert_pytest_fails_with(['--mpl', test_file, '--mpl-generate-summary'],
295+
output = assert_pytest_fails_with(['--mpl', test_file, '--mpl-generate-summary=html'],
296296
"doesn't match hash FAIL in library")
297297
# We didn't specify a baseline dir so we shouldn't attempt to find one
298298
print_message = "A summary of the failed tests can be found at:"

0 commit comments

Comments
 (0)