Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit dc3bdf5

Browse filesBrowse files
story645timhoffm
andcommitted
Update doc/api/testing_api.rst
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
1 parent cf4e812 commit dc3bdf5
Copy full SHA for dc3bdf5

File tree

2 files changed

+31
-3
lines changed
Filter options

2 files changed

+31
-3
lines changed

‎doc/api/testing_api.rst

Copy file name to clipboardExpand all lines: doc/api/testing_api.rst
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@
3939
:show-inheritance:
4040

4141

42-
Data container testing fixtures
42+
Testing with optional dependencies
4343
==================================
44+
For more information on fixtures, see :external+pytest:ref:`pytest fixtures <about-fixtures>`.
4445

4546
.. autofunction:: matplotlib.testing.conftest.pd
4647
.. autofunction:: matplotlib.testing.conftest.xr

‎lib/matplotlib/testing/conftest.py

Copy file name to clipboardExpand all lines: lib/matplotlib/testing/conftest.py
+29-2Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,20 @@ def mpl_test_settings(request):
8282

8383
@pytest.fixture
8484
def pd():
85-
"""Fixture to import and configure pandas."""
85+
"""
86+
Fixture to import and configure pandas. Using this fixture, the test is skipped when
87+
pandas is not installed. Use this fixture instead of importing pandas in test files.
88+
89+
Examples
90+
--------
91+
Request the pandas fixture by passing in ``pd`` as an argument to the test ::
92+
93+
def test_matshow_pandas(pd):
94+
95+
df = pd.DataFrame({'x':[1,2,3], 'y':[4,5,6]})
96+
im = plt.figure().subplots().matshow(df)
97+
np.testing.assert_array_equal(im.get_array(), df)
98+
"""
8699
pd = pytest.importorskip('pandas')
87100
try:
88101
from pandas.plotting import (
@@ -95,6 +108,20 @@ def pd():
95108

96109
@pytest.fixture
97110
def xr():
98-
"""Fixture to import xarray."""
111+
"""
112+
Fixture to import xarray so that the test is skipped when xarray is not installed.
113+
Use this fixture instead of importing xrray in test files.
114+
115+
Examples
116+
--------
117+
Request the xarray fixture by passing in ``xr`` as an argument to the test ::
118+
119+
def test_imshow_xarray(xr):
120+
121+
ds = xr.DataArray(np.random.randn(2, 3))
122+
im = plt.figure().subplots().imshow(ds)
123+
np.testing.assert_array_equal(im.get_array(), ds)
124+
"""
125+
99126
xr = pytest.importorskip('xarray')
100127
return xr

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.