-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7973 from QuLogic/pytest-fixture
TST: Convert test decorators to pytest fixtures
- Loading branch information
Showing
49 changed files
with
114 additions
and
344 deletions.
There are no files selected for viewing
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
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
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 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 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 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 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.