Skip to content

update testing helpers #16990

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 1 commit into from
May 18, 2020

Conversation

terencehonles
Copy link
Contributor

PR Summary

Pulling out of #16922 and expanding to be a bit more helpful (but will probably create additional discussion which I am am providing the context below)

  • @matplotlib.testing.decorators.image_comparison now prints the path to the diff image so it is easier to find, so that newcomers know it exists.
  • update tests.py to give more information about how it should be run if matplotlib is not installed already.
  • update matplotlib.test to return -1 instead of raising ImportErrors if there are preconditions not met. This allows the error messages to not be buried by the stack traces, is still a return value which would signify an error, and does not conflict with the range used by pytest.ExitCode (0-5) allowing callers to distinguish different pytest error codes from an error starting up pytest
  • move the import pytest check out of matplotlib._init_tests because it is only called via matplotlib.test and via pytest's configure handler, and it is more appropriate and can be handled more gracefully if it is checked in matplotlib.test

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@terencehonles terencehonles force-pushed the update-testing-helpers branch from 555514a to a51bab7 Compare April 1, 2020 06:44
- `@matplotlib.testing.decorators.image_comparison` now prints the path
  to the diff image so it is easier to find, so that newcomers know it
  exists.

- update `tests.py` to give more information about how it should be run
  if matplotlib is not installed already.

- update `matplotlib.test` to return -1 instead of raising ImportErrors
  if there are preconditions not met. This allows the error messages to
  not be buried by the stack traces, is still a return value which would
  signify an error, and does not conflict with the range used by
  `pytest.ExitCode` (0-5) allowing callers to distinguish different
  pytest error codes from an error starting up pytest

- move the `import pytest` check out of `matplotlib._init_tests` because
  it is only called via `matplotlib.test` and via pytest's configure
  handler, and it is more appropriate and can be handled more gracefully
  if it is checked in `matplotlib.test`
@terencehonles terencehonles force-pushed the update-testing-helpers branch from a51bab7 to 30f7b65 Compare April 3, 2020 01:00

@cbook._delete_parameter("3.2", "switch_backend_warn")
@cbook._delete_parameter("3.3", "recursionlimit")
def test(verbosity=None, coverage=False, switch_backend_warn=True,
recursionlimit=0, **kwargs):
"""Run the matplotlib test suite."""
_init_tests()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But now you don't make the warning about FreeType. Why did the pytest import check have to move into this function and not just stay in _init_tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You do still get the import warning about FreeType because the pytest configure calls _init_tests

matplotlib._init_tests()

As originally written the _init_tests will be called twice: Once before the logger is set up (here), and then again by pytest (linked above) which by then logging is being captured. I didn't believe _init_tests needed to be called here because it doesn't raise an exception and you're not going to see the logs since they aren't set up at this point. If the warning in _init_tests isn't actually a warning it should be emitted in a way that a user can see it (currently it isn't).

The reason I moved the pytest import into this function is so this function doesn't need to blindly capture ImportError and can return -1 for pytest not being installed. This is all detailed in the PR description if you would like to read that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@QuLogic thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@QuLogic Does this satisfy your question? I've put this on the call agenda for tomorrow, but if you're ok with this, we don't have to spend time on it.

import pytest
except ImportError:
print("matplotlib.test requires pytest to run.")
return -1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am skeptical about the API change, but this function is already returning an error code so any users of this will likely already be expecting to handle error codes so I expect it will do little harm.

Copy link
Contributor Author

@terencehonles terencehonles May 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was basically my position. It wasn't obvious to me why this was "broken" and I thought it wasn't used anymore. It was, but I didn't have the right environment. I then sought to clarify the whole process until getting pytest to run. I was contemplating keeping the same API for this part, but the code would be less clear and as you noted the test function will already return error codes on pytest errors

@tacaswell tacaswell added this to the v3.3.0 milestone May 18, 2020
@tacaswell tacaswell merged commit 1a6ef99 into matplotlib:master May 18, 2020
@tacaswell
Copy link
Member

I am happy that the freetype checks are still happening via pytest_configure in conftest.py.

Thanks @terencehonles !

@terencehonles terencehonles deleted the update-testing-helpers branch May 19, 2020 02:42
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.

4 participants