diff options
| author | Claude Paroz <claude@2xlibre.net> | 2014-06-06 20:12:23 +0200 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2014-06-14 13:43:39 +0200 |
| commit | 4b4524291adbc78ab880317124803fc37a2e414a (patch) | |
| tree | 71e03eadb772e9a4dc1e74c2d00a7465b469ffc1 /docs | |
| parent | cbff097bd91fad42c7231026968f686598b1d7a2 (diff) | |
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.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/releases/1.8.txt | 11 | ||||
| -rw-r--r-- | docs/topics/testing/advanced.txt | 27 |
2 files changed, 35 insertions, 3 deletions
diff --git a/docs/releases/1.8.txt b/docs/releases/1.8.txt index 437c27189f..c54e1d5ab0 100644 --- a/docs/releases/1.8.txt +++ b/docs/releases/1.8.txt @@ -294,6 +294,17 @@ you don't have to keep compatibility with older Django versions, it's better to implement the new :meth:`~django.core.management.BaseCommand.add_arguments` method as described in :doc:`/howto/custom-management-commands`. +Custom test management command arguments through test runner +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The method to add custom arguments to the `test` management command through the +test runner has changed. Previously, you could provide an `option_list` class +variable on the test runner to add more arguments (à la :py:mod:`optparse`). +Now to implement the same behavior, you have to create an +``add_arguments(cls, parser)`` class method on the test runner and call +``parser.add_argument`` to add any custom arguments, as parser is now an +:py:class:`argparse.ArgumentParser` instance. + Miscellaneous ~~~~~~~~~~~~~ diff --git a/docs/topics/testing/advanced.txt b/docs/topics/testing/advanced.txt index ac6e15557a..46d0913084 100644 --- a/docs/topics/testing/advanced.txt +++ b/docs/topics/testing/advanced.txt @@ -333,9 +333,15 @@ execute and tear down the test suite. runner, ensure it accepts ``**kwargs``. Your test runner may also define additional command-line options. - If you add an ``option_list`` attribute to a subclassed test runner, - those options will be added to the list of command-line options that - the :djadmin:`test` command can use. + Create or override an ``add_arguments(cls, parser)`` class method and add + custom arguments by calling ``parser.add_argument()`` inside the method, so + that the :djadmin:`test` command will be able to use those arguments. + + .. versionchanged:: 1.8 + + Previously, you had to provide an ``option_list`` attribute to a + subclassed test runner to add options to the list of command-line + options that the :djadmin:`test` command could use. Attributes ~~~~~~~~~~ @@ -372,6 +378,12 @@ Attributes management command's ``OptionParser`` for parsing arguments. See the documentation for Python's ``optparse`` module for more details. + .. deprecated:: 1.8 + + You should now override the :meth:`~DiscoverRunner.add_arguments` class + method to add custom arguments accepted by the :djadmin:`test` + management command. + Methods ~~~~~~~ @@ -389,6 +401,15 @@ Methods This method should return the number of tests that failed. +.. classmethod:: DiscoverRunner.add_arguments(parser) + + .. versionadded:: 1.8 + + Override this class method to add custom arguments accepted by the + :djadmin:`test` management command. See + :py:meth:`argparse.ArgumentParser.add_argument()` for details about adding + arguments to a parser. + .. method:: DiscoverRunner.setup_test_environment(**kwargs) Sets up the test environment by calling |
