diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2011-06-10 08:26:05 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2011-06-10 08:26:05 +0000 |
| commit | 046ffa483ed63faae7b31e7e2cf618f88a3312ba (patch) | |
| tree | d90ffd710a4bbcd5db38469eb144efcb1c85e178 /tests | |
| parent | b56ef75088e17fa3555766e92a6747411ccd738c (diff) | |
Fixed #16185, #15675 -- Added the ability for test runners to define custom options, and to specify a custom test runner at the command line. Thanks to Dmitry Jemerov and Mikołaj Siedlarek for the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16352 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/regressiontests/test_runner/tests.py | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/tests/regressiontests/test_runner/tests.py b/tests/regressiontests/test_runner/tests.py index b3d6475697..4261e44d7f 100644 --- a/tests/regressiontests/test_runner/tests.py +++ b/tests/regressiontests/test_runner/tests.py @@ -2,12 +2,15 @@ Tests for django test runner """ import StringIO +from optparse import make_option import warnings from django.core.exceptions import ImproperlyConfigured +from django.core.management import call_command from django.test import simple from django.test.utils import get_warnings_state, restore_warnings_state from django.utils import unittest +from regressiontests.admin_scripts.tests import AdminScriptTestCase class DjangoTestRunnerTests(unittest.TestCase): @@ -128,3 +131,75 @@ class DependencyOrderingTests(unittest.TestCase): self.assertRaises(ImproperlyConfigured, simple.dependency_ordered, raw, dependencies=dependencies) + +class MockTestRunner(object): + invoked = False + + def __init__(self, *args, **kwargs): + pass + + def run_tests(self, test_labels, extra_tests=None, **kwargs): + MockTestRunner.invoked = True + + +class ManageCommandTests(unittest.TestCase): + + def test_custom_test_runner(self): + call_command('test', 'sites', + testrunner='regressiontests.test_runner.tests.MockTestRunner') + self.assertTrue(MockTestRunner.invoked, + "The custom test runner has not been invoked") + + +class CustomOptionsTestRunner(simple.DjangoTestSuiteRunner): + option_list = ( + make_option('--option_a','-a', action='store', dest='option_a', default='1'), + make_option('--option_b','-b', action='store', dest='option_b', default='2'), + make_option('--option_c','-c', action='store', dest='option_c', default='3'), + ) + + def __init__(self, verbosity=1, interactive=True, failfast=True, option_a=None, option_b=None, option_c=None, **kwargs): + super(CustomOptionsTestRunner, self).__init__(verbosity=verbosity, interactive=interactive, + failfast=failfast) + self.option_a = option_a + self.option_b = option_b + self.option_c = option_c + + def run_tests(self, test_labels, extra_tests=None, **kwargs): + print "%s:%s:%s" % (self.option_a, self.option_b, self.option_c) + + +class CustomTestRunnerOptionsTests(AdminScriptTestCase): + + def setUp(self): + settings = { + 'TEST_RUNNER': '\'regressiontests.test_runner.tests.CustomOptionsTestRunner\'', + } + self.write_settings('settings.py', sdict=settings) + + def tearDown(self): + self.remove_settings('settings.py') + + def test_default_options(self): + args = ['test', '--settings=settings'] + out, err = self.run_django_admin(args) + self.assertNoOutput(err) + self.assertOutput(out, '1:2:3') + + def test_default_and_given_options(self): + args = ['test', '--settings=settings', '--option_b=foo'] + out, err = self.run_django_admin(args) + self.assertNoOutput(err) + self.assertOutput(out, '1:foo:3') + + def test_option_name_and_value_separated(self): + args = ['test', '--settings=settings', '--option_b', 'foo'] + out, err = self.run_django_admin(args) + self.assertNoOutput(err) + self.assertOutput(out, '1:foo:3') + + def test_all_options_given(self): + args = ['test', '--settings=settings', '--option_a=bar', '--option_b=foo', '--option_c=31337'] + out, err = self.run_django_admin(args) + self.assertNoOutput(err) + self.assertOutput(out, 'bar:foo:31337') |
