-
Notifications
You must be signed in to change notification settings - Fork 48
Test against JSON summaries (and bugfixes) #134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In hybrid mode only hashes can affect result. Clarify what `--mpl-results-always` does and when it's used.
Cadair
approved these changes
Feb 9, 2022
Looks great! Thanks so much! |
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds a new test module and fixes a number of bugs that were discovered by the new tests.
New test module (
tests/subtests/
)pytest-mpl can output JSON summaries (
--mpl-generate-summary=json
) which contain lots of machine readable information relating to the internal state of the plugin while it was run. This test moduletest_subtest.py
runs the test filesubtest.py
multiple times with different combinations of pytest-mpl arguments. After each test, it compares the outputted JSON summary to a "baseline" JSON summary for that specific combination of arguments (summaries/*.json
).These tests are very sensitive to deviations in the documented behaviour of the pytest-mpl configuration arguments. And the exact behaviour of each configuration (such as images, hashes or both) can be asserted.
By using various helper functions defined in
helpers.py
, the baseline summaries are not specific to the MPL/FreeType versions. This is implemented through regex in the log output, and by replacing baseline hashes with hashes in a version specific baseline hash libraryhashes/*.json
and replacing result hashes with hashes in a version specific "baseline" result hash libraryresult_hashes/*.json
.Bugs
These new tests have already uncovered a number of bugs which I have also fixed in this PR for convenience:
Bug 1 [hash comparison mode]
If pytest-mpl is configured to only compare to a hash library (i.e. not hybrid mode), a passing hash comparison will always attempt to find a baseline image in the default baseline directory and compare against it. (However, a failing hash comparison behaves as documented.)
Bug 2 [hybrid mode]
When in hybrid mode, a passing hash comparison leads to an image comparison test, while the documentation says that only a failing hash comparison should do that.
Closes #132
Bug 3 [hybrid mode]
When in hybrid mode, a missing hash does not lead to an image comparison test. This behaviour is not documented, and would not always be desired.
Fixes for Bugs 1-3
These are fixed by restructuring
compare_image_to_hash_library
inpytest_mpl/plugin.py
. I removed some redundant code and made the code pathway easier to follow. These changes are fully tested in the newtests/subtests/
and the existing tests only needed a few trivial changes to log output wording to pass.Interactive HTML
When in image comparison or hash comparison only mode, some elements in the HTML are irrelevant. I have added some extra conditionals to the Jinja templates to improve this. You can see the HTML output of the new tests here. Also fixed a major bug where the template doesn't render if a test doesn't have a hash comparison result!
Documentation
I have clarified the behaviour of hybrid mode, generating HTML summaries, and results always. Also added documentation for
--mpl-baseline-relative
. I have not changed any of the documented behaviour, only clarified behaviour or documented undocumented behaviour.Updates to tox configuration
tox.ini
to pin these Matplotlib versions.--mpl
to make sure both pass. However, tests which call a pytest subprocess run exactly the same both times. I've marked the non--mpl
run so it doesn't call these, decreasing run time.@Cadair Let me know if you want anything clarified, and sorry for the large diff!