Skip to content

Commit d19ed96

Browse files
committed
Have pytest_collection_modifyitems take into account Django test classes
1 parent d6d8804 commit d19ed96

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+
# If Django is not configured we don't need to bother
421+
if not django_settings_is_configured():
422+
return
423+
424+
from django.test import TestCase, TransactionTestCase
425+
420426
def get_order_number(test):
427+
if 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)