Skip to content

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 22 commits into from
Feb 9, 2022

Conversation

ConorMacBride
Copy link
Member

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 module test_subtest.py runs the test file subtest.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 library hashes/*.json and replacing result hashes with hashes in a version specific "baseline" result hash library result_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 in pytest_mpl/plugin.py. I removed some redundant code and made the code pathway easier to follow. These changes are fully tested in the new tests/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

  • The mpl34 and mpl35 environments weren't actually defined even though they are used in the CI. I've added these to tox.ini to pin these Matplotlib versions.
  • Pytest is run twice, with and without --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!

@Cadair
Copy link
Contributor

Cadair commented Feb 9, 2022

Looks great! Thanks so much!

@Cadair Cadair merged commit 23a52c3 into matplotlib:master Feb 9, 2022
@ConorMacBride ConorMacBride mentioned this pull request May 20, 2022
16 tasks
@bjlittle bjlittle mentioned this pull request May 21, 2022
@ConorMacBride ConorMacBride deleted the hybrid-mode-baseline branch February 28, 2023 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hybrid mode is always comparing to baseline images
2 participants