Skip to content

Commit 4cd379b

Browse files
committed
Integrate interactive HTML
1 parent 14be93b commit 4cd379b

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

pytest_mpl/plugin.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@
4343

4444
import pytest
4545

46-
SUPPORTED_FORMATS = {'html', 'json'}
46+
from pytest_mpl.summary.html import generate_summary_html
47+
48+
SUPPORTED_FORMATS = {'html', 'json', 'basic-html'}
4749

4850
SHAPE_MISMATCH_ERROR = """Error: Image dimensions did not match.
4951
Expected shape: {expected_shape}
@@ -162,7 +164,7 @@ def pytest_addoption(parser):
162164
group.addoption('--mpl-generate-summary', action='store',
163165
help="Generate a summary report of any failed tests"
164166
", in --mpl-results-path. The type of the report should be "
165-
"specified. Supported types are `html` and `json`. "
167+
"specified. Supported types are `html`, `json` and `basic-html`. "
166168
"Multiple types can be specified separated by commas.")
167169

168170
results_path_help = "directory for test results, relative to location where py.test is run"
@@ -732,11 +734,11 @@ def generate_stats(self):
732734
raise ValueError(f"Unknown test status '{test['status']}'.")
733735
self._test_stats = stats
734736

735-
def generate_summary_html(self):
737+
def generate_summary_basic_html(self):
736738
"""
737739
Generate a simple HTML table of the failed test results
738740
"""
739-
html_file = self.results_dir / 'fig_comparison.html'
741+
html_file = self.results_dir / 'fig_comparison_basic.html'
740742
with open(html_file, 'w') as f:
741743

742744
passed = f"{self._test_stats['passed']} passed"
@@ -849,7 +851,10 @@ def pytest_unconfigure(self, config):
849851
summary = self.generate_summary_json()
850852
print(f"A JSON report can be found at: {summary}")
851853
if 'html' in self.generate_summary:
852-
summary = self.generate_summary_html()
854+
summary = generate_summary_html(self._test_results, self.results_dir)
855+
print(f"A summary of the failed tests can be found at: {summary}")
856+
if 'basic-html' in self.generate_summary:
857+
summary = self.generate_summary_basic_html()
853858
print(f"A summary of the failed tests can be found at: {summary}")
854859

855860

setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ long_description_content_type = text/x-rst
2323
[options]
2424
zip_safe = True
2525
packages = find:
26+
include_package_data = True
2627
python_requires = >=3.6
2728
install_requires =
2829
pytest
2930
matplotlib
3031
importlib_resources;python_version<'3.8'
3132
packaging
33+
Jinja2
3234

3335
[options.entry_points]
3436
pytest11 =

tests/test_pytest_mpl.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,11 +441,16 @@ def test_results_always(tmpdir):
441441
code = call_pytest(['--mpl', test_file, '--mpl-results-always',
442442
rf'--mpl-hash-library={hash_library}',
443443
rf'--mpl-baseline-path={baseline_dir_abs}',
444-
'--mpl-generate-summary=html,json',
444+
'--mpl-generate-summary=html,json,basic-html',
445445
rf'--mpl-results-path={results_path.strpath}'])
446446
assert code == 0 # hashes correct, so all should pass
447447

448-
comparison_file = results_path.join('fig_comparison.html')
448+
# assert files for interactive HTML exist
449+
assert results_path.join('fig_comparison.html').exists()
450+
assert results_path.join('styles.css').exists()
451+
assert results_path.join('extra.js').exists()
452+
453+
comparison_file = results_path.join('fig_comparison_basic.html')
449454
with open(comparison_file, 'r') as f:
450455
html = f.read()
451456

0 commit comments

Comments
 (0)