Implement a hacky first pass at discovery.
authorJames Westby <james.westby@canonical.com>
Sun, 6 Jun 2010 23:20:08 +0000 (00:20 +0100)
committerJames Westby <james.westby@canonical.com>
Sun, 6 Jun 2010 23:20:08 +0000 (00:20 +0100)
python/subunit/run.py

index 01c0b0e9e6b35911b06db3e3a534769a1cbe41de..5c440eb9bd796a6b808dc98a3f33df5e6652cf7a 100755 (executable)
@@ -24,6 +24,12 @@ import sys
 
 from subunit import TestProtocolClient, get_default_formatter
 
+try:
+    import discover
+    has_discover = True
+except ImportError:
+    has_discover = False
+
 
 class SubunitTestRunner(object):
     def __init__(self, stream=sys.stdout):
@@ -38,10 +44,20 @@ class SubunitTestRunner(object):
 
 if __name__ == '__main__':
     import optparse
-    from unittest import TestProgram
+    from unittest import TestProgram, TestSuite
     parser = optparse.OptionParser(__doc__)
-    args = parser.parse_args()[1]
+    if has_discover:
+        parser.add_option("--discover", dest="discover", action="store_true",
+                help="Use test discovery on the given testspec.")
+    options, args = parser.parse_args()
     stream = get_default_formatter()
     runner = SubunitTestRunner(stream)
+    if has_discover and options.discover:
+        loader = discover.DiscoveringTestLoader()
+        test = TestSuite()
+        for arg in args:
+            test.addTest(loader.discover(arg))
+        result = runner.run(test)
+        sys.exit(not result.wasSuccessful())
     program = TestProgram(module=None, argv=[sys.argv[0]] + args,
                           testRunner=runner)