8000 Add support for classes with pytest 7 by ConorMacBride · Pull Request #164 · matplotlib/pytest-mpl · GitHub
[go: up one dir, main page]

Skip to content

Add support for classes with pytest 7 #164

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 5 commits into from
Jun 14, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add failure test for running inside class
  • Loading branch information
ConorMacBride committed Jun 1, 2022
commit 91d23c44b5dcbbe4c7180eb57a342a107dc2dbb6
43 changes: 43 additions & 0 deletions tests/test_pytest_mpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,3 +486,46 @@ def test_results_always(tmpdir):
assert image and not image_exists
assert image not in html
assert json_res[json_image_key] is None


TEST_FAILING_CLASS = """
import pytest
import matplotlib.pyplot as plt
class TestClass(object):
@pytest.mark.mpl_image_compare
def test_fails(self):
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.plot([1, 2, 3])
return fig
"""

TEST_FAILING_CLASS_SETUP_METHOD = """
import pytest
import matplotlib.pyplot as plt
class TestClassWithSetup:
def setup_method(self, method):
self.x = [1, 2, 3]
@pytest.mark.mpl_image_compare
def test_fails(self):
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.plot(self.x)
return fig
"""


@pytest.mark.parametrize("code", [TEST_FAILING_CLASS, TEST_FAILING_CLASS_SETUP_METHOD])
def test_class_fail(code, tmpdir):

test_file = tmpdir.join('test.py').strpath
with open(test_file, 'w') as f:
f.write(code)

# Assert fails if hash library missing
assert_pytest_fails_with(['--mpl', test_file, '--mpl-hash-library=/not/a/path'],
"Can't find hash library at path")

# If we don't use --mpl option, the test should succeed
code = call_pytest([test_file])
assert code == 0
0