Am Samstag, den 05.04.2008, 19:53 -0400 schrieb Phillip J. Eby:
> At 05:15 PM 4/5/2008 +0200, Klaus Zimmermann wrote:
> >Hi all,
> >
> >for our nightly build system I needed the capability to use a different
> >test runner, namely one that outputs junit compatible xml files.
> >In order to support that through the setup.py test command I hacked on
> >setuptools.
> >
> >Is there a simpler way to do this?
> >If not you might want to consider attached patch for addition
> >(Should be against latest svn.)
>
> Add documentation to the patch and you've got yourself a deal. :)
Updated patch attached.
Have fun,
Klaus
diff --git a/setup.py b/setup.py
index 4a73beb..813b037 100755
--- a/setup.py
+++ b/setup.py
@@ -53,6 +53,7 @@ setup(
"include_package_data = setuptools.dist:assert_bool",
"dependency_links = setuptools.dist:assert_string_list",
"test_loader = setuptools.dist:check_importable",
+ "test_runner = setuptools.dist:check_importable",
],
"egg_info.writers": [
"PKG-INFO = setuptools.command.egg_info:write_pkg_info",
diff --git a/setuptools.egg-info/entry_points.txt b/setuptools.egg-info/entry_points.txt
index f7367e0..84f8f83 100755
--- a/setuptools.egg-info/entry_points.txt
+++ b/setuptools.egg-info/entry_points.txt
@@ -40,6 +40,7 @@ svn_cvs = setuptools.command.sdist:_default_revctrl
dependency_links = setuptools.dist:assert_string_list
entry_points = setuptools.dist:check_entry_points
extras_require = setuptools.dist:check_extras
+test_runner = setuptools.dist:check_importable
package_data = setuptools.dist:check_package_data
install_requires = setuptools.dist:check_requirements
include_package_data = setuptools.dist:assert_bool
diff --git a/setuptools.txt b/setuptools.txt
index a5ef502..88542a2 100755
--- a/setuptools.txt
+++ b/setuptools.txt
@@ -388,6 +388,14 @@ unless you need the associated ``setuptools`` feature.
as long as you use the ``tests_require`` option to ensure that the package
containing the loader class is available when the ``test`` command is run.
+.. _test_runner:
+
+``test_runner``
+ If you want to use another test runner, this can be specified here.
+ Format is the same as for ``test_loader``_, i.e. entry point format.
+ The runner must be instatiable without arguments and must be usable as a
+ ``unittest`` test runner.
+
``eager_resources``
A list of strings naming resources that should be extracted together, if
any of them is needed, or if any C extensions included in the project are
@@ -2263,7 +2271,7 @@ By default, tests will be run in the "verbose" mode of the ``unittest``
package's text test runner, but you can get the "quiet" mode (just dots) if
you supply the ``-q`` or ``--quiet`` option, either as a global option to
the setup script (e.g. ``setup.py -q test``) or as an option for the ``test``
-command itself (e.g. ``setup.py test -q``). There is one other option
+command itself (e.g. ``setup.py test -q``). Other options are
available:
``--test-suite=NAME, -s NAME``
@@ -2279,6 +2287,11 @@ available:
If you did not set a ``test_suite`` in your ``setup()`` call, and do not
provide a ``--test-suite`` option, an error will occur.
+``--test-runner=NAME, -r NAME``
+ Specify the test runner to use. The default can be set as an argument to
+ ``setup()``. See ``test_runner``_. If this is not set the standard
+ ``unittest.TextTestRunner`` will be used.
+
.. _upload:
diff --git a/setuptools/command/test.py b/setuptools/command/test.py
index db918da..6fcf1df 100644
--- a/setuptools/command/test.py
+++ b/setuptools/command/test.py
@@ -49,9 +49,11 @@ class test(Command):
('test-module=','m', "Run 'test_suite' in specified module"),
('test-suite=','s',
"Test suite to run (e.g. 'some_module.test_suite')"),
+ ('test-runner=','r', "Test runner to use"),
]
def initialize_options(self):
+ self.test_runner = None
self.test_suite = None
self.test_module = None
self.test_loader = None
@@ -77,7 +79,8 @@ class test(Command):
self.test_loader = getattr(self.distribution,'test_loader',None)
if self.test_loader is None:
self.test_loader = "setuptools.command.test:ScanningLoader"
-
+ if self.test_runner is None:
+ self.test_runner = getattr(self.distribution,'test_runner',None)
def with_project_on_sys_path(self, func):
@@ -125,40 +128,16 @@ class test(Command):
import unittest
loader_ep = EntryPoint.parse("x="+self.test_loader)
loader_class = loader_ep.load(require=False)
- unittest.main(
- None, None, [unittest.__file__]+self.test_args,
- testLoader = loader_class()
- )
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ if self.test_runner == None:
+ unittest.main(
+ None, None, [unittest.__file__]+self.test_args,
+ testLoader = loader_class()
+ )
+ else:
+ runner_ep = EntryPoint.parse("x="+self.test_runner)
+ runner_class = runner_ep.load(require=False)
+ unittest.main(
+ None, None, [unittest.__file__]+self.test_args,
+ testRunner = runner_class(),
+ testLoader = loader_class()
+ )
_______________________________________________
Distutils-SIG maillist - [email protected]
http://mail.python.org/mailman/listinfo/distutils-sig