Skip to content

Commit c1edb78

Browse files
committed
ENH: Add test for results directory.
1 parent d988327 commit c1edb78

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tests/test_pytest_mpl.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,35 @@ def test_fails(tmpdir):
8686
assert code == 0
8787

8888

89+
TEST_OUTPUT_DIR = """
90+
import pytest
91+
import matplotlib.pyplot as plt
92+
@pytest.mark.mpl_image_compare
93+
def test_output_dir():
94+
fig = plt.figure()
95+
ax = fig.add_subplot(1, 1, 1)
96+
ax.plot([1, 2, 3])
97+
return fig
98+
"""
99+
100+
101+
def test_output_dir(tmpdir):
102+
test_file = tmpdir.join('test.py').strpath
103+
with open(test_file, 'w') as f:
104+
f.write(TEST_OUTPUT_DIR)
105+
106+
# When we run the test, we should get output images where we specify
107+
output_dir = tmpdir.join('test_output_dir').strpath
108+
code = subprocess.call('py.test --mpl-results-path={0} --mpl {1}'.format(output_dir, test_file),
109+
shell=True)
110+
111+
assert code != 0
112+
assert os.path.exists(output_dir)
113+
114+
# Listdir() is to get the random name that the output for the one test is written into
115+
assert os.path.exists(os.path.join(output_dir, os.listdir(output_dir)[0], 'test_output_dir.png'))
116+
117+
89118
TEST_GENERATE = """
90119
import pytest
91120
import matplotlib.pyplot as plt

0 commit comments

Comments
 (0)