@@ -176,13 +176,13 @@ def pytest_load_initial_conftests(early_config, parser, args):
176
176
early_config .addinivalue_line (
177
177
'markers' ,
178
178
'django_db(transaction=False): Mark the test as using '
179
- 'the django test database. The *transaction* argument marks will '
180
- "allow you to use real transactions in the test like Django's "
179
+ 'the Django test database. The *transaction* argument '
180
+ "allows you to use real transactions in the test like with Django's "
181
181
'TransactionTestCase.' )
182
182
early_config .addinivalue_line (
183
183
'markers' ,
184
184
'urls(modstr): Use a different URLconf for this test, similar to '
185
- ' the `urls` attribute of Django `TestCase` objects. *modstr* is '
185
+ " the `urls` attribute of Django's `TestCase` objects. *modstr* is "
186
186
'a string specifying the module of a URL config, e.g. '
187
187
'"my_app.test_urls".' )
188
188
early_config .addinivalue_line (
@@ -339,6 +339,34 @@ def pytest_runtest_setup(item):
339
339
_disable_class_methods (cls )
340
340
341
341
342
+ def pytest_collection_modifyitems (session , config , items ):
343
+ def get_marker_transaction (test ):
344
+ marker = test .get_marker ("django_db" )
345
+ if marker :
346
+ validate_django_db (marker )
347
+ return marker .transaction
348
+ return None
349
+
350
+ def has_fixture (test , fixture ):
351
+ funcargnames = getattr (test , 'funcargnames' , None )
352
+ return funcargnames and fixture in funcargnames
353
+
354
+ def get_order_number (test ):
355
+ if get_marker_transaction (test ) is True :
356
+ return 1
357
+ if has_fixture (test , 'transactional_db' ):
358
+ return 1
359
+
360
+ if get_marker_transaction (test ) is False :
361
+ return 0
362
+ if has_fixture (test , 'db' ):
363
+ return 0
364
+
365
+ return 2
366
+
367
+ items [:] = sorted (items , key = get_order_number )
368
+
369
+
342
370
@pytest .fixture (autouse = True , scope = 'session' )
343
371
def django_test_environment (request ):
344
372
"""
0 commit comments