[Zope3-checkins]
SVN: zope.testing/branches/list-modules/src/zope/testing/testrunner
Implement a --list-modules option that lists all modules
matching your pattern,
Marius Gedminas
marius at pov.lt
Fri Jan 12 14:46:53 EST 2007
Log message for revision 71982:
Implement a --list-modules option that lists all modules matching your pattern,
but does not actually run any tests. It has one downside: it ignores layer
filtering.
This used to live on the mgedmin-fixes branch:
svn merge -r 71952:71953 svn+ssh://svn.zope.org/repos/main/zope.testing/branches/mgedmin-fixes .
Changed:
U zope.testing/branches/list-modules/src/zope/testing/testrunner-test-selection.txt
U zope.testing/branches/list-modules/src/zope/testing/testrunner.py
-=-
Modified: zope.testing/branches/list-modules/src/zope/testing/testrunner-test-selection.txt
===================================================================
--- zope.testing/branches/list-modules/src/zope/testing/testrunner-test-selection.txt 2007-01-12 19:42:54 UTC (rev 71981)
+++ zope.testing/branches/list-modules/src/zope/testing/testrunner-test-selection.txt 2007-01-12 19:46:53 UTC (rev 71982)
@@ -336,6 +336,10 @@
Ran 20 tests with 0 failures and 0 errors in 0.004 seconds.
False
+
+Test Levels
+-----------
+
Sometimes, There are tests that you don't want to run by default.
For example, you might have tests that take a long time. Tests can
have a level attribute. If no level is specified, a level of 1 is
@@ -486,3 +490,65 @@
test_y0 (sampletests.test_one)
Ran 39 tests with 0 failures and 0 errors in 0.009 seconds.
False
+
+
+Listing Selected Tests
+----------------------
+
+When you're trying to figure out why the test you want is not matched by the
+pattern you specified, it is convenient to see which test modules match your
+specifications.
+
+ >>> sys.argv = 'test -s sample3 --list-modules'.split()
+ >>> from zope.testing import testrunner
+ >>> testrunner.run(defaults)
+ sample3.sampletests
+ False
+
+ >>> sys.argv = 'test -m test1 --list-modules'.split()
+ >>> from zope.testing import testrunner
+ >>> testrunner.run(defaults)
+ sample1.sampletests.test1
+ sample1.sampletests.test11
+ sample1.sampletests.test111
+ sample1.sampletests.test112
+ sample1.sampletests.test12
+ sample1.sampletests.test121
+ sample1.sampletests.test122
+ sampletests.test1
+ sampletests.test11
+ sampletests.test111
+ sampletests.test112
+ sampletests.test12
+ sampletests.test121
+ sampletests.test122
+ False
+
+Note that --layer has no effect, as --list-modules doesn't actually import the
+modules for performance reasons.
+
+ >>> sys.argv = 'test --layer 122 -s sample1 --list-modules'.split()
+ >>> from zope.testing import testrunner
+ >>> testrunner.run(defaults)
+ sample1.sampletestsf
+ sample1.sample11.sampletests
+ sample1.sample13.sampletests
+ sample1.sampletests.test1
+ sample1.sampletests.test11
+ sample1.sampletests.test111
+ sample1.sampletests.test112
+ sample1.sampletests.test12
+ sample1.sampletests.test121
+ sample1.sampletests.test122
+ sample1.sampletests.test_one
+ False
+
+For the same reason even if you specify a -t option that excludes all tests
+from a module, it may still be listed by --list-modules:
+
+ >>> sys.argv = 'test -s sample3 -t reallynosuchtestthere --list-modules'.split()
+ >>> from zope.testing import testrunner
+ >>> testrunner.run(defaults)
+ sample3.sampletests
+ False
+
Modified: zope.testing/branches/list-modules/src/zope/testing/testrunner.py
===================================================================
--- zope.testing/branches/list-modules/src/zope/testing/testrunner.py 2007-01-12 19:42:54 UTC (rev 71981)
+++ zope.testing/branches/list-modules/src/zope/testing/testrunner.py 2007-01-12 19:46:53 UTC (rev 71982)
@@ -377,6 +377,11 @@
remove_stale_bytecode(options)
+ if options.list_modules:
+ for module in find_modules(options):
+ print module
+ return True
+
tests_by_layer_name = find_tests(options, found_suites)
ran = 0
@@ -1086,8 +1091,7 @@
yield (suite, layer)
break
-
-def find_suites(options):
+def find_modules(options):
for fpath, package in find_test_files(options):
for (prefix, prefix_package) in options.prefix:
if fpath.startswith(prefix) and package == prefix_package:
@@ -1105,35 +1109,41 @@
else:
continue
- try:
- module = import_name(module_name)
- except KeyboardInterrupt:
- raise
- except:
- suite = StartUpFailure(
- options, module_name,
- sys.exc_info()[:2]
- + (sys.exc_info()[2].tb_next.tb_next,),
+ yield module_name
+ break
+
+def find_suites(options, found_modules=None):
+ if found_modules is None:
+ found_modules = find_modules(options)
+ for module_name in found_modules:
+ try:
+ module = import_name(module_name)
+ except KeyboardInterrupt:
+ raise
+ except:
+ suite = StartUpFailure(
+ options, module_name,
+ sys.exc_info()[:2]
+ + (sys.exc_info()[2].tb_next.tb_next,),
+ )
+ else:
+ try:
+ suite = getattr(module, options.suite_name)()
+ if isinstance(suite, unittest.TestSuite):
+ check_suite(suite, module_name)
+ else:
+ raise TypeError(
+ "Invalid test_suite, %r, in %s"
+ % (suite, module_name)
)
- else:
- try:
- suite = getattr(module, options.suite_name)()
- if isinstance(suite, unittest.TestSuite):
- check_suite(suite, module_name)
- else:
- raise TypeError(
- "Invalid test_suite, %r, in %s"
- % (suite, module_name)
- )
- except KeyboardInterrupt:
- raise
- except:
- suite = StartUpFailure(
- options, module_name, sys.exc_info()[:2]+(None,))
+ except KeyboardInterrupt:
+ raise
+ except:
+ suite = StartUpFailure(
+ options, module_name, sys.exc_info()[:2]+(None,))
- yield suite
- break
+ yield suite
def check_suite(suite, module_name):
for x in suite:
@@ -1423,10 +1433,16 @@
string that does not match "bc", and vice versa). The option can be
specified multiple test-module filters. Test modules matching any of
the test filters are searched. If no test-module filter is specified,
-then all test moduless are used.
+then all test modules are used.
""")
searching.add_option(
+ '--list-modules', action="store_true", dest='list_modules', default=False,
+ help="""\
+List all test modules that matched your filters. Do not run any tests.
+""")
+
+searching.add_option(
'--test', '-t', action="append", dest='test',
help="""\
Specify a test filter as a regular expression. This is a
@@ -1794,7 +1810,7 @@
options.test = [test_filter]
if positional:
- parser.error("Too mant positional arguments")
+ parser.error("Too many positional arguments")
options.ignore_dir = dict([(d,1) for d in options.ignore_dir])
options.test_file_pattern = re.compile(options.test_file_pattern).search
More information about the Zope3-Checkins
mailing list