@@ -245,14 +245,14 @@ def pytest_load_initial_conftests(early_config, parser, args):
245245 early_config .addinivalue_line (
246246 "markers" ,
247247 "django_db(transaction=False): Mark the test as using "
248- "the django test database. The *transaction* argument marks will "
248+ "the Django test database. The *transaction* argument marks will "
249249 "allow you to use real transactions in the test like Django's "
250250 "TransactionTestCase." ,
251251 )
252252 early_config .addinivalue_line (
253253 "markers" ,
254254 "urls(modstr): Use a different URLconf for this test, similar to "
255- "the `urls` attribute of Django `TestCase` objects. *modstr* is "
255+ "the `urls` attribute of Django's `TestCase` objects. *modstr* is "
256256 "a string specifying the module of a URL config, e.g. "
257257 '"my_app.test_urls".' ,
258258 )
@@ -425,6 +425,30 @@ def pytest_runtest_setup(item):
425425 _disable_class_methods (item .cls )
426426
427427
428+ def pytest_collection_modifyitems (session , config , items ):
429+ def get_order_number (test ):
430+ marker_db = test .get_closest_marker ('django_db' )
431+ if marker_db :
432+ transaction = validate_django_db (marker_db )[0 ]
433+ if transaction is True :
434+ return 1
435+ else :
436+ transaction = None
437+
438+ fixtures = getattr (test , 'funcargnames' , [])
439+ if "transactional_db" in fixtures :
440+ return 1
441+
442+ if transaction is False :
443+ return 0
444+ if "db" in fixtures :
445+ return 0
446+
447+ return 2
448+
449+ items [:] = sorted (items , key = get_order_number )
450+
451+
428452@pytest .fixture (autouse = True , scope = "session" )
429453def django_test_environment (request ):
430454 """
0 commit comments