Skip to content

Commit c5eeb37

Browse files
committed
Checks for tags on any SimpleTestCase not just TransactionTestCase
1 parent 9047da6 commit c5eeb37

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

pytest_django/plugin.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,8 @@ def pytest_report_header(config: pytest.Config) -> list[str] | None:
378378

379379

380380
# Convert Django test tags on test classes to pytest marks.
381+
# Unlike the Django test runner, we only check tags on Django
382+
# test classes, to keep the plugin's effect contained.
381383
def pytest_collectstart(collector: pytest.Collector) -> None:
382384
if "django" not in sys.modules:
383385
return
@@ -389,9 +391,9 @@ def pytest_collectstart(collector: pytest.Collector) -> None:
389391
if not tags:
390392
return
391393

392-
from django.test import TransactionTestCase
394+
from django.test import SimpleTestCase
393395

394-
if not issubclass(collector.obj, TransactionTestCase):
396+
if not issubclass(collector.obj, SimpleTestCase):
395397
return
396398

397399
for tag in tags:
@@ -410,9 +412,9 @@ def pytest_itemcollected(item: pytest.Item) -> None:
410412
if not tags:
411413
return
412414

413-
from django.test import TransactionTestCase
415+
from django.test import SimpleTestCase
414416

415-
if not issubclass(item.cls, TransactionTestCase):
417+
if not issubclass(item.cls, SimpleTestCase):
416418
return
417419

418420
for tag in tags:

tests/test_unittest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import pytest
2-
from django.test import TestCase, tag
2+
from django.test import SimpleTestCase, TestCase, tag
33

44
from .helpers import DjangoPytester
55

@@ -58,7 +58,7 @@ def tearDown(self) -> None:
5858

5959

6060
@tag("tag1", "tag2")
61-
class TestDjangoTagsToPytestMarkers(TestCase):
61+
class TestDjangoTagsToPytestMarkers(SimpleTestCase):
6262
"""Django test tags are converted to Pytest markers, at the class & method
6363
levels."""
6464

0 commit comments

Comments
 (0)