|
3 | 3 | import json
|
4 | 4 | import subprocess
|
5 | 5 | from pathlib import Path
|
| 6 | +from unittest import TestCase |
6 | 7 |
|
7 | 8 | import matplotlib
|
8 | 9 | import matplotlib.ft2font
|
@@ -259,6 +260,23 @@ def test_succeeds(self):
|
259 | 260 | return fig
|
260 | 261 |
|
261 | 262 |
|
| 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 | + |
262 | 280 | # hashlib
|
263 | 281 |
|
264 | 282 | @pytest.mark.skipif(not hash_library.exists(), reason="No hash library for this mpl version")
|
@@ -514,8 +532,27 @@ def test_fails(self):
|
514 | 532 | return fig
|
515 | 533 | """
|
516 | 534 |
|
| 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 | + |
517 | 550 |
|
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 | +]) |
519 | 556 | def test_class_fail(code, tmpdir):
|
520 | 557 |
|
521 | 558 | test_file = tmpdir.join('test.py').strpath
|
|
0 commit comments