|
47 | 47 | ] |
48 | 48 |
|
49 | 49 |
|
| 50 | +def xdist_args(n_workers): |
| 51 | + try: |
| 52 | + import xdist |
| 53 | + if n_workers is None: |
| 54 | + return ["-p", "no:xdist"] |
| 55 | + else: |
| 56 | + return ["-n", str(n_workers)] |
| 57 | + except ImportError: |
| 58 | + return [] |
| 59 | + |
| 60 | + |
50 | 61 | def run_subtest(baseline_summary_name, tmp_path, args, summaries=None, xfail=True, |
51 | 62 | has_result_hashes=False, generating_hashes=False, testing_hashes=False, n_xdist_workers=None, |
52 | 63 | update_baseline=UPDATE_BASELINE, update_summary=UPDATE_SUMMARY): |
@@ -112,14 +123,7 @@ def run_subtest(baseline_summary_name, tmp_path, args, summaries=None, xfail=Tru |
112 | 123 | shutil.copy(expected_result_hash_library, baseline_hash_library) |
113 | 124 | transform_hashes(baseline_hash_library) |
114 | 125 |
|
115 | | - try: |
116 | | - import xdist |
117 | | - if n_xdist_workers is None: |
118 | | - pytest_args += ["-p", "no:xdist"] |
119 | | - else: |
120 | | - pytest_args += ["-n", str(n_xdist_workers)] |
121 | | - except ImportError: |
122 | | - pass |
| 126 | + pytest_args.extend(xdist_args(n_xdist_workers)) |
123 | 127 |
|
124 | 128 | # Run the test and record exit status |
125 | 129 | status = subprocess.call(pytest_args + mpl_args + args) |
@@ -363,3 +367,19 @@ def test_html_run_generate_hashes_only(tmp_path): |
363 | 367 | # Run a hybrid mode test last so if generating hash libraries, it includes all the hashes. |
364 | 368 | def test_hybrid(tmp_path): |
365 | 369 | run_subtest('test_hybrid', tmp_path, [HASH_LIBRARY_FLAG, BASELINE_IMAGES_FLAG_ABS], testing_hashes=True) |
| 370 | + |
| 371 | + |
| 372 | +@pytest.mark.parametrize("num_workers", [None, 0, 1, 2]) |
| 373 | +def test_html_no_json(tmp_path, num_workers): |
| 374 | + # Previous tests require JSON summary to be generated to function correctly. |
| 375 | + # This test ensures HTML summary generation works without JSON summary. |
| 376 | + results_path = tmp_path / 'results' |
| 377 | + results_path.mkdir() |
| 378 | + mpl_args = ['--mpl', rf'--mpl-results-path={results_path.as_posix()}', |
| 379 | + '--mpl-generate-summary=html', *xdist_args(num_workers)] |
| 380 | + subprocess.call([sys.executable, '-m', 'pytest', str(TEST_FILE), *mpl_args]) |
| 381 | + assert not (tmp_path / 'results' / 'results.json').exists() |
| 382 | + html_path = tmp_path / 'results' / 'fig_comparison.html' |
| 383 | + assert html_path.exists() |
| 384 | + assert html_path.stat().st_size > 200_000 |
| 385 | + assert "Baseline image differs" in html_path.read_text() |
0 commit comments