Skip to content

Commit b0f62ba

Browse files
committed
Clarify behaviour
In hybrid mode only hashes can affect result. Clarify what `--mpl-results-always` does and when it's used.
1 parent ab4bd47 commit b0f62ba

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

README.rst

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ directly in the right directory.
7575
With a Hash Library
7676
^^^^^^^^^^^^^^^^^^^
7777

78-
Instead of comparing to baseline images, you can instead compare against a json
79-
library of sha256 hashes. This has the advantage of not having to check baseline
78+
Instead of comparing to baseline images, you can instead compare against a JSON
79+
library of SHA-256 hashes. This has the advantage of not having to check baseline
8080
images into the repository with the tests, or download them from a remote
8181
source.
8282

@@ -91,8 +91,11 @@ Hybrid Mode: Hashes and Images
9191
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9292

9393
It is possible to configure both hashes and baseline images. In this scenario
94-
the hashes will be compared first, with the baseline images only used if the hash
95-
comparison fails.
94+
only the hash comparison can determine the test result. If the hash comparison
95+
fails, the test will fail, however a comparison to the baseline image will be
96+
carried out so the actual difference can be seen. If the hash comparison passes,
97+
the comparison to the baseline image is skipped (unless **results always** is
98+
configured).
9699

97100
This is especially useful if the baseline images are external to the repository
98101
containing the tests, and are accessed via HTTP. In this situation, if the hashes
@@ -104,7 +107,7 @@ without having to modify the external images.
104107
Running Tests
105108
^^^^^^^^^^^^^
106109

107-
Once tests are written with either baseline images or a hash library to compare
110+
Once tests are written with baseline images, a hash library, or both to compare
108111
against, the tests can be run with::
109112

110113
pytest --mpl
@@ -118,12 +121,15 @@ Generating a Test Summary
118121
^^^^^^^^^^^^^^^^^^^^^^^^^
119122

120123
By specifying the ``--mpl-generate-summary=html`` CLI argument, a HTML summary
121-
page will be generated showing the result, log entry and RMS of each test,
122-
and the hashes if configured. The baseline, diff and result image for each
123-
failing test will be shown. If **Results always** is configured
124-
(see section below), images for passing tests will also be shown.
125-
If no baseline images are configured, just the result images will
126-
be displayed.
124+
page will be generated showing the test result, log entry and generated result
125+
image. When in the (default) image comparison mode, the baseline image, diff
126+
image and RMS (if any), and tolerance of each test will also be shown.
127+
When in the hash comparison mode, the baseline hash and result hash will
128+
also be shown. When in hybrid mode, all of these are included.
129+
130+
When generating a HTML summary, the ``--mpl-results-always`` option is
131+
automatically applied (see section below). Therefore images for passing
132+
tests will also be shown.
127133

128134
+---------------+---------------+---------------+
129135
| |html all| | |html filter| | |html result| |
@@ -199,20 +205,25 @@ decorator takes precedence.
199205
Results always
200206
^^^^^^^^^^^^^^
201207

202-
By default, result images are only generated for tests that fail.
208+
By default, result images are only saved for tests that fail.
203209
Passing ``--mpl-results-always`` to pytest will force result images
204-
to be generated for all tests, even for tests that pass.
205-
If a baseline image exists, a diff image will also be generated.
206-
All of these images will be shown in the summary (if requested).
210+
to be saved for all tests, even for tests that pass.
211+
212+
When in **hybrid mode**, even if a test passes hash comparison,
213+
a comparison to the baseline image will also be carried out,
214+
with the baseline image and diff image (if image comparison fails)
215+
saved for all tests. This secondary comparison will not affect
216+
the success status of the test.
207217

208-
This option is useful for always *comparing* the result images again
218+
This option is useful for always *comparing* the result images against
209219
the baseline images, while only *assessing* the tests against the
210220
hash library.
211221
If you only update your baseline images after merging a PR, this
212222
option means that the generated summary will always show how the
213223
PR affects the baseline images, with the success status of each
214224
test (based on the hash library) also shown in the generated
215-
summary.
225+
summary. This option is applied automatically when generating
226+
a HTML summary.
216227

217228
Base style
218229
^^^^^^^^^^

pytest_mpl/plugin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def pytest_addoption(parser):
140140
group.addoption('--mpl-results-path', help=results_path_help, action='store')
141141
parser.addini('mpl-results-path', help=results_path_help)
142142

143-
results_always_help = ("Always generate result images, not just for failed tests. "
143+
results_always_help = ("Always compare to baseline images and save result images, even for passing tests. "
144144
"This option is automatically applied when generating a HTML summary.")
145145
group.addoption('--mpl-results-always', action='store_true',
146146
help=results_always_help)
@@ -272,7 +272,7 @@ def __init__(self,
272272
if len(unsupported_formats) > 0:
273273
raise ValueError(f"The mpl summary type(s) '{sorted(unsupported_formats)}' "
274274
"are not supported.")
275-
# Ignore `results_always` and always save result images for HTML output
275+
# When generating HTML always apply `results_always`
276276
if generate_summary & {'html', 'basic-html'}:
277277
results_always = True
278278
self.generate_summary = generate_summary

0 commit comments

Comments
 (0)