Skip to content

Commit 3a22789

Browse files
committed
Add passing and failing tests for unittest.TestCase
1 parent af96b02 commit 3a22789

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

tests/test_pytest_mpl.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import json
44
import subprocess
55
from pathlib import Path
6+
from unittest import TestCase
67

78
import matplotlib
89
import matplotlib.ft2font
@@ -259,6 +260,23 @@ def test_succeeds(self):
259260
return fig
260261

261262

263+
class TestClassWithTestCase(TestCase):
264+
265+
# Regression test for a bug that occurred when using unittest.TestCase
266+
267+
def setUp(self):
268+
self.x = [1, 2, 3]
269+
270+
@pytest.mark.mpl_image_compare(baseline_dir=baseline_dir_local,
271+
filename='test_succeeds.png',
272+
tolerance=DEFAULT_TOLERANCE)
273+
def test_succeeds(self):
274+
fig = plt.figure()
275+
ax = fig.add_subplot(1, 1, 1)
276+
ax.plot(self.x)
277+
return fig
278+
279+
262280
# hashlib
263281

264282
@pytest.mark.skipif(not hash_library.exists(), reason="No hash library for this mpl version")
@@ -514,8 +532,27 @@ def test_fails(self):
514532
return fig
515533
"""
516534

535+
TEST_FAILING_UNITTEST_TESTCASE = """
536+
from unittest import TestCase
537+
import pytest
538+
import matplotlib.pyplot as plt
539+
class TestClassWithTestCase(TestCase):
540+
def setUp(self):
541+
self.x = [1, 2, 3]
542+
@pytest.mark.mpl_image_compare
543+
def test_fails(self):
544+
fig = plt.figure()
545+
ax = fig.add_subplot(1, 1, 1)
546+
ax.plot(self.x)
547+
return fig
548+
"""
549+
517550

518-
@pytest.mark.parametrize("code", [TEST_FAILING_CLASS, TEST_FAILING_CLASS_SETUP_METHOD])
551+
@pytest.mark.parametrize("code", [
552+
TEST_FAILING_CLASS,
553+
TEST_FAILING_CLASS_SETUP_METHOD,
554+
TEST_FAILING_UNITTEST_TESTCASE,
555+
])
519556
def test_class_fail(code, tmpdir):
520557

521558
test_file = tmpdir.join('test.py').strpath

0 commit comments

Comments
 (0)