Skip to content

Commit

Permalink
Make DatabaseSetupPlugin work with other plugins
Browse files Browse the repository at this point in the history
Make tests pass when run “with profile plugin”
  • Loading branch information
millerdev committed Oct 7, 2015
1 parent b8568ed commit 3dde874
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
23 changes: 22 additions & 1 deletion django_nose/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,11 @@ def _bundle_fixtures(self, fftc_tests):

return tests

def prepareTest(self, test):
def prepareTestRunner(self, runner):
"""Get a runner that reorders tests before running them"""
return _DatabaseSetupTestRunner(self, runner)

def group_by_database_setup(self, test):
"""Reorder the tests."""
test_groups = self._group_test_cases_by_type(test)
suites = []
Expand All @@ -339,6 +343,23 @@ def prepareTest(self, test):
return suites[0] if len(suites) == 1 else ContextSuite(suites)


class _DatabaseSetupTestRunner(object):
"""A test runner that groups tests by database setup
This is a helper class that reorders tests for efficient database
setup. It modifies the test suite before any other plugins have a
chance to wrap it in the `prepareTest` hook.
"""

def __init__(self, plugin, real_runner):
self.plugin = plugin
self.runner = real_runner

def run(self, test):
test = self.plugin.group_by_database_setup(test)
return self.runner.run(test)


def get_test_context(context_path, tests, runner):
"""Make a test context.
Expand Down
10 changes: 6 additions & 4 deletions django_nose/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@

import nose.core

from django_nose.plugin import DjangoSetUpPlugin, ResultPlugin
from django_nose.plugin import DatabaseSetUpPlugin
from django_nose.plugin import DjangoSetUpPlugin, ResultPlugin
from django_nose.utils import uses_mysql

try:
Expand Down Expand Up @@ -285,13 +285,15 @@ class BasicNoseRunner(BaseRunner):
def run_suite(self, nose_argv):
"""Run the test suite."""
result_plugin = ResultPlugin()
plugins_to_add = [DjangoSetUpPlugin(self), result_plugin]
plugins_to_add = [
DjangoSetUpPlugin(self),
DatabaseSetUpPlugin(self),
result_plugin,
]

for plugin in _get_plugins_from_settings():
plugins_to_add.append(plugin)

plugins_to_add.append(DatabaseSetUpPlugin(self))

try:
django.setup()
except AttributeError:
Expand Down

0 comments on commit 3dde874

Please sign in to comment.