Skip to content

Commit be176ba

Browse files
committed
Make DatabaseSetupPlugin work with other plugins
Fixes “with profile plugin” tests
1 parent b8568ed commit be176ba

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

django_nose/plugin.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,11 @@ def _bundle_fixtures(self, fftc_tests):
312312

313313
return tests
314314

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):
316320
"""Reorder the tests."""
317321
test_groups = self._group_test_cases_by_type(test)
318322
suites = []
@@ -339,6 +343,24 @@ def prepareTest(self, test):
339343
return suites[0] if len(suites) == 1 else ContextSuite(suites)
340344

341345

346+
class _DatabaseSetupTestRunner(object):
347+
348+
"""A test runner that groups tests by database setup.
349+
350+
This is a helper class that reorders tests for efficient database
351+
setup. It modifies the test suite before any other plugins have a
352+
chance to wrap it in the `prepareTest` hook.
353+
"""
354+
355+
def __init__(self, plugin, real_runner):
356+
self.plugin = plugin
357+
self.runner = real_runner
358+
359+
def run(self, test):
360+
test = self.plugin.group_by_database_setup(test)
361+
return self.runner.run(test)
362+
363+
342364
def get_test_context(context_path, tests, runner):
343365
"""Make a test context.
344366

django_nose/runner.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242

4343
import nose.core
4444

45-
from django_nose.plugin import DjangoSetUpPlugin, ResultPlugin
4645
from django_nose.plugin import DatabaseSetUpPlugin
46+
from django_nose.plugin import DjangoSetUpPlugin, ResultPlugin
4747
from django_nose.utils import uses_mysql
4848

4949
try:
@@ -285,13 +285,15 @@ class BasicNoseRunner(BaseRunner):
285285
def run_suite(self, nose_argv):
286286
"""Run the test suite."""
287287
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+
]
289293

290294
for plugin in _get_plugins_from_settings():
291295
plugins_to_add.append(plugin)
292296

293-
plugins_to_add.append(DatabaseSetUpPlugin(self))
294-
295297
try:
296298
django.setup()
297299
except AttributeError:

0 commit comments

Comments
 (0)