From c5eeb37d95492709a6591cc47ad26569d5a3d014 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Tue, 7 Nov 2023 14:03:39 +0200 Subject: [PATCH] Checks for tags on any `SimpleTestCase` not just `TransactionTestCase` --- pytest_django/plugin.py | 10 ++++++---- tests/test_unittest.py | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/pytest_django/plugin.py b/pytest_django/plugin.py index 5197abb5..6f45ee95 100644 --- a/pytest_django/plugin.py +++ b/pytest_django/plugin.py @@ -378,6 +378,8 @@ def pytest_report_header(config: pytest.Config) -> list[str] | None: # Convert Django test tags on test classes to pytest marks. +# Unlike the Django test runner, we only check tags on Django +# test classes, to keep the plugin's effect contained. def pytest_collectstart(collector: pytest.Collector) -> None: if "django" not in sys.modules: return @@ -389,9 +391,9 @@ def pytest_collectstart(collector: pytest.Collector) -> None: if not tags: return - from django.test import TransactionTestCase + from django.test import SimpleTestCase - if not issubclass(collector.obj, TransactionTestCase): + if not issubclass(collector.obj, SimpleTestCase): return for tag in tags: @@ -410,9 +412,9 @@ def pytest_itemcollected(item: pytest.Item) -> None: if not tags: return - from django.test import TransactionTestCase + from django.test import SimpleTestCase - if not issubclass(item.cls, TransactionTestCase): + if not issubclass(item.cls, SimpleTestCase): return for tag in tags: diff --git a/tests/test_unittest.py b/tests/test_unittest.py index 0fb4f7c9..38200d61 100644 --- a/tests/test_unittest.py +++ b/tests/test_unittest.py @@ -1,5 +1,5 @@ import pytest -from django.test import TestCase, tag +from django.test import SimpleTestCase, TestCase, tag from .helpers import DjangoPytester @@ -58,7 +58,7 @@ def tearDown(self) -> None: @tag("tag1", "tag2") -class TestDjangoTagsToPytestMarkers(TestCase): +class TestDjangoTagsToPytestMarkers(SimpleTestCase): """Django test tags are converted to Pytest markers, at the class & method levels."""