-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Convert test decorators to pytest fixtures #7973
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
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from __future__ import (absolute_import, division, print_function, | ||
unicode_literals) | ||
|
||
from matplotlib.tests.conftest import mpl_test_settings |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from __future__ import (absolute_import, division, print_function, | ||
unicode_literals) | ||
|
||
import pytest | ||
|
||
import matplotlib | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def mpl_test_settings(request): | ||
from matplotlib.testing.decorators import _do_cleanup | ||
|
||
original_units_registry = matplotlib.units.registry.copy() | ||
original_settings = matplotlib.rcParams.copy() | ||
|
||
backend = None | ||
backend_marker = request.keywords.get('backend') | ||
if backend_marker is not None: | ||
assert len(backend_marker.args) == 1, \ | ||
"Marker 'backend' must specify 1 backend." | ||
backend = backend_marker.args[0] | ||
prev_backend = matplotlib.get_backend() | ||
|
||
style = 'classic' | ||
style_marker = request.keywords.get('style') | ||
if style_marker is not None: | ||
assert len(style_marker.args) == 1, \ | ||
"Marker 'style' must specify 1 style." | ||
style = style_marker.args[0] | ||
|
||
matplotlib.testing.setup() | ||
if backend is not None: | ||
# This import must come after setup() so it doesn't load the default | ||
# backend prematurely. | ||
import matplotlib.pyplot as plt | ||
plt.switch_backend(backend) | ||
matplotlib.style.use(style) | ||
try: | ||
yield | ||
finally: | ||
if backend is not None: | ||
import matplotlib.pyplot as plt | ||
plt.switch_backend(prev_backend) | ||
_do_cleanup(original_units_registry, | ||
original_settings) |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's happening there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When switching to the automatic fixture and dropping any
@cleanup
s, the tests fail with nose because they don't get that setup done. However, see next comment.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for being dense, but why does this variable even exist? Why do we have a default whitelist of tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's used for
matplotlib.test()
; in the next PR I just set it to the top-level modules.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to keep
matplotlib.test()
? Even if we do, can we just makematplotlib.test()
fully rely on pytest's test discovery?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's why I pass only the top-level modules; but we still need to pass something because this works on the installed version and we need to hit both
matplotlib
andmpl_toolkits
. I wouldn't be against deprecatingmatplotlib.test()
and the top-leveltests.py
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get it.
After the general conversion, do we expect
nosetests
to correctly run the tests?matplotlib.test()
(... andtests.py
at the same time).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The answer to the first question is no as far as our own tests are concerned. But
matplotlib.test()
andtests.py
will work with pytest in #7974. I have no idea how many people may or may not be using that method, so I don't know whether we should remove it or not.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we already broke backcompat on our tests by having a requirement on pytest, and by making it not possible to run the test suite by running
nosetests
. I simply do not understand why we can't just break it a bit more to get rid of old warts... that we're planning to get rid of anyways.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, I'm not against it, but I think this discussion really belongs on #7974 where that code is actually changed.