@@ -245,14 +245,14 @@ def pytest_load_initial_conftests(early_config, parser, args):
245
245
early_config .addinivalue_line (
246
246
"markers" ,
247
247
"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 "
249
249
"allow you to use real transactions in the test like Django's "
250
250
"TransactionTestCase." ,
251
251
)
252
252
early_config .addinivalue_line (
253
253
"markers" ,
254
254
"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 "
256
256
"a string specifying the module of a URL config, e.g. "
257
257
'"my_app.test_urls".' ,
258
258
)
@@ -425,6 +425,30 @@ def pytest_runtest_setup(item):
425
425
_disable_class_methods (item .cls )
426
426
427
427
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
+
428
452
@pytest .fixture (autouse = True , scope = "session" )
429
453
def django_test_environment (request ):
430
454
"""
0 commit comments