Skip to content

Simplify cleanup decorator implementation. #11292

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 2 commits into from
Jun 5, 2018

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented May 23, 2018

Introduce a single private _cleanup_cm contextmanager and use it to
implement CleanupTestCase and @cleanup.

Use warnings.catch_warnings to avoid completely destroying a
preexisting warnings filter, instead just restoring the filter that
existed before the test started.

Use matplotlib.style.context to restore the style at exit, as it
relies on rc_context which is ultimately more efficient than
rcParams.update as it skips revalidation.

Deprecate CleanupTest (and implement it in terms of CleanupTestCase), as
it is clearly a nose-oriented base class that could have been deprecated
at the same time as ImageComparisonTest.

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 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

@anntzer anntzer added this to the v3.0 milestone May 23, 2018
@anntzer anntzer force-pushed the testingwarnings branch from 393aa4c to 7fb1832 Compare May 23, 2018 06:52
Introduce a single private `_cleanup_cm` contextmanager and use it to
implement `CleanupTestCase` and `@cleanup`.

Use `warnings.catch_warnings` to avoid completely destroying a
preexisting warnings filter, instead just restoring the filter that
existed before the test started.

Use `matplotlib.style.context` to restore the style at exit, as it
relies on rc_context which is ultimately more efficient than
`rcParams.update` as it skips revalidation.

Deprecate CleanupTest (and implement it in terms of CleanupTestCase), as
it is clearly a nose-oriented base class that could have been deprecated
at the same time as ImageComparisonTest.
@anntzer anntzer force-pushed the testingwarnings branch from 7fb1832 to f564af7 Compare May 31, 2018 03:27
Otherwise, rcParams cannot be deprecated without spamming stderr with
one warning per test.
@anntzer
Copy link
Contributor Author

anntzer commented May 31, 2018

@efiring @tacaswell This PR fixes the warnings issue (and more generally makes it possible, among other things, to deprecate rcParams without jumping through hoops to avoid the same issue arising again).

@efiring
Copy link
Member

efiring commented May 31, 2018

Thank you. All this arcane testing machinery is beyond my knowledge and abilities, but I'm glad to see that it kills the spam.

@phobson phobson merged commit 59bfd35 into matplotlib:master Jun 5, 2018
@anntzer anntzer deleted the testingwarnings branch June 5, 2018 21:35
@anntzer anntzer mentioned this pull request Jun 5, 2018
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants