Skip to content

Commit 775df6f

Browse files
committed
Have pytest_collection_modifyitems take into account Django test classes
1 parent 5c21625 commit 775df6f

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

pytest_django/plugin.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,20 @@ def pytest_runtest_setup(item):
417417

418418
@pytest.hookimpl(tryfirst=True)
419419
def pytest_collection_modifyitems(items):
420+
order_django_test_classes = False
421+
if django_settings_is_configured():
422+
_setup_django()
423+
from django.test import TestCase, TransactionTestCase
424+
order_django_test_classes = True
425+
420426
def get_order_number(test):
427+
if order_django_test_classes and hasattr(test, "cls") and test.cls:
428+
# Beware, TestCase is a subclass of TransactionTestCase
429+
if issubclass(test.cls, TestCase):
430+
return 0
431+
if issubclass(test.cls, TransactionTestCase):
432+
return 1
433+
421434
marker_db = test.get_closest_marker('django_db')
422435
if marker_db:
423436
transaction = validate_django_db(marker_db)[0]

0 commit comments

Comments
 (0)