@@ -189,13 +189,13 @@ def pytest_load_initial_conftests(early_config, parser, args):
189
189
early_config .addinivalue_line (
190
190
'markers' ,
191
191
'django_db(transaction=False): Mark the test as using '
192
- 'the django test database. The *transaction* argument marks will '
193
- "allow you to use real transactions in the test like Django's "
192
+ 'the Django test database. The *transaction* argument '
193
+ "allows you to use real transactions in the test like with Django's "
194
194
'TransactionTestCase.' )
195
195
early_config .addinivalue_line (
196
196
'markers' ,
197
197
'urls(modstr): Use a different URLconf for this test, similar to '
198
- ' the `urls` attribute of Django `TestCase` objects. *modstr* is '
198
+ " the `urls` attribute of Django's `TestCase` objects. *modstr* is "
199
199
'a string specifying the module of a URL config, e.g. '
200
200
'"my_app.test_urls".' )
201
201
early_config .addinivalue_line (
@@ -352,6 +352,34 @@ def pytest_runtest_setup(item):
352
352
_disable_class_methods (cls )
353
353
354
354
355
+ def pytest_collection_modifyitems (session , config , items ):
356
+ def get_marker_transaction (test ):
357
+ marker = test .get_marker ("django_db" )
358
+ if marker :
359
+ validate_django_db (marker )
360
+ return marker .transaction
361
+ return None
362
+
363
+ def has_fixture (test , fixture ):
364
+ funcargnames = getattr (test , 'funcargnames' , None )
365
+ return funcargnames and fixture in funcargnames
366
+
367
+ def get_order_number (test ):
368
+ if get_marker_transaction (test ) is True :
369
+ return 1
370
+ if has_fixture (test , 'transactional_db' ):
371
+ return 1
372
+
373
+ if get_marker_transaction (test ) is False :
374
+ return 0
375
+ if has_fixture (test , 'db' ):
376
+ return 0
377
+
378
+ return 2
379
+
380
+ items [:] = sorted (items , key = get_order_number )
381
+
382
+
355
383
@pytest .fixture (autouse = True , scope = 'session' )
356
384
def django_test_environment (request ):
357
385
"""
0 commit comments