File tree 2 files changed +28
-5
lines changed 2 files changed +28
-5
lines changed Original file line number Diff line number Diff line change @@ -312,7 +312,11 @@ def _bundle_fixtures(self, fftc_tests):
312
312
313
313
return tests
314
314
315
- def prepareTest (self , test ):
315
+ def prepareTestRunner (self , runner ):
316
+ """Get a runner that reorders tests before running them"""
317
+ return _DatabaseSetupTestRunner (self , runner )
318
+
319
+ def group_by_database_setup (self , test ):
316
320
"""Reorder the tests."""
317
321
test_groups = self ._group_test_cases_by_type (test )
318
322
suites = []
@@ -339,6 +343,23 @@ def prepareTest(self, test):
339
343
return suites [0 ] if len (suites ) == 1 else ContextSuite (suites )
340
344
341
345
346
+ class _DatabaseSetupTestRunner (object ):
347
+ """A test runner that groups tests by database setup
348
+
349
+ This is a helper class that reorders tests for efficient database
350
+ setup. It modifies the test suite before any other plugins have a
351
+ chance to wrap it in the `prepareTest` hook.
352
+ """
353
+
354
+ def __init__ (self , plugin , real_runner ):
355
+ self .plugin = plugin
356
+ self .runner = real_runner
357
+
358
+ def run (self , test ):
359
+ test = self .plugin .group_by_database_setup (test )
360
+ return self .runner .run (test )
361
+
362
+
342
363
def get_test_context (context_path , tests , runner ):
343
364
"""Make a test context.
344
365
Original file line number Diff line number Diff line change 42
42
43
43
import nose .core
44
44
45
- from django_nose .plugin import DjangoSetUpPlugin , ResultPlugin
46
45
from django_nose .plugin import DatabaseSetUpPlugin
46
+ from django_nose .plugin import DjangoSetUpPlugin , ResultPlugin
47
47
from django_nose .utils import uses_mysql
48
48
49
49
try :
@@ -285,13 +285,15 @@ class BasicNoseRunner(BaseRunner):
285
285
def run_suite (self , nose_argv ):
286
286
"""Run the test suite."""
287
287
result_plugin = ResultPlugin ()
288
- plugins_to_add = [DjangoSetUpPlugin (self ), result_plugin ]
288
+ plugins_to_add = [
289
+ DjangoSetUpPlugin (self ),
290
+ DatabaseSetUpPlugin (self ),
291
+ result_plugin ,
292
+ ]
289
293
290
294
for plugin in _get_plugins_from_settings ():
291
295
plugins_to_add .append (plugin )
292
296
293
- plugins_to_add .append (DatabaseSetUpPlugin (self ))
294
-
295
297
try :
296
298
django .setup ()
297
299
except AttributeError :
You can’t perform that action at this time.
0 commit comments