mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
Converted test management command to argparse
Keeping backwards compatibility with test_runner.option_list is tricky and would imply transforming an optparse.Option to an argparse.Action. I choose to introduce a backwards incompatible change because it only affects testing, not runtime behavior.
This commit is contained in:
parent
cbff097bd9
commit
4b4524291a
5 changed files with 86 additions and 50 deletions
|
@ -3,7 +3,6 @@ Tests for django test runner
|
|||
"""
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from optparse import make_option
|
||||
import unittest
|
||||
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
|
@ -152,11 +151,6 @@ class ManageCommandTests(unittest.TestCase):
|
|||
|
||||
|
||||
class CustomOptionsTestRunner(runner.DiscoverRunner):
|
||||
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,
|
||||
|
@ -165,6 +159,12 @@ class CustomOptionsTestRunner(runner.DiscoverRunner):
|
|||
self.option_b = option_b
|
||||
self.option_c = option_c
|
||||
|
||||
@classmethod
|
||||
def add_arguments(cls, parser):
|
||||
parser.add_argument('--option_a', '-a', action='store', dest='option_a', default='1'),
|
||||
parser.add_argument('--option_b', '-b', action='store', dest='option_b', default='2'),
|
||||
parser.add_argument('--option_c', '-c', action='store', dest='option_c', default='3'),
|
||||
|
||||
def run_tests(self, test_labels, extra_tests=None, **kwargs):
|
||||
print("%s:%s:%s" % (self.option_a, self.option_b, self.option_c))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue