@@ -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,32 @@ 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_marker_transaction (test ):
430
+ marker = test .get_closest_marker ('django_db' )
431
+ if marker :
432
+ return validate_django_db (marker )[0 ]
433
+ return None
434
+
435
+ def has_fixture (test , fixture ):
436
+ return fixture in getattr (test , 'funcargnames' , [])
437
+
438
+ def get_order_number (test ):
439
+ if get_marker_transaction (test ) is True :
440
+ return 1
441
+ if has_fixture (test , "transactional_db" ):
442
+ return 1
443
+
444
+ if get_marker_transaction (test ) is False :
445
+ return 0
446
+ if has_fixture (test , "db" ):
447
+ return 0
448
+
449
+ return 2
450
+
451
+ items [:] = sorted (items , key = get_order_number )
452
+
453
+
428
454
@pytest .fixture (autouse = True , scope = "session" )
429
455
def django_test_environment (request ):
430
456
"""
0 commit comments