summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorCollin Winter <collinw@gmail.com>2007-04-25 17:29:52 (GMT)
committerCollin Winter <collinw@gmail.com>2007-04-25 17:29:52 (GMT)
commitc2898c5a678e6dd00c3e0b18a214fcd7a3533800 (patch)
treedfaedbddee7b0ef79a19527788b8a720658e79bb /Lib
parent0d4c06e06e5ee1f3bb1fa8068114bd700d74864a (diff)
downloadcpython-c2898c5a678e6dd00c3e0b18a214fcd7a3533800.zip
cpython-c2898c5a678e6dd00c3e0b18a214fcd7a3533800.tar.gz
cpython-c2898c5a678e6dd00c3e0b18a214fcd7a3533800.tar.bz2
Standardize on test.test_support.run_unittest() (as opposed to a mix of run_unittest() and run_suite()). Also, add functionality to run_unittest() that admits usage of unittest.TestLoader.loadTestsFromModule().
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/README32
-rw-r--r--Lib/test/test_base64.py12
-rw-r--r--Lib/test/test_bsddb3.py10
-rw-r--r--Lib/test/test_codecencodings_cn.py6
-rw-r--r--Lib/test/test_codecencodings_hk.py4
-rw-r--r--Lib/test/test_codecencodings_jp.py8
-rw-r--r--Lib/test/test_codecencodings_kr.py6
-rw-r--r--Lib/test/test_codecencodings_tw.py4
-rw-r--r--Lib/test/test_codecmaps_cn.py5
-rw-r--r--Lib/test/test_codecmaps_hk.py4
-rw-r--r--Lib/test/test_codecmaps_jp.py8
-rw-r--r--Lib/test/test_codecmaps_kr.py6
-rw-r--r--Lib/test/test_codecmaps_tw.py5
-rw-r--r--Lib/test/test_contextlib.py6
-rw-r--r--Lib/test/test_ctypes.py4
-rw-r--r--Lib/test/test_datetime.py34
-rw-r--r--Lib/test/test_email.py4
-rw-r--r--Lib/test/test_email_codecs.py2
-rw-r--r--Lib/test/test_email_renamed.py4
-rw-r--r--Lib/test/test_gettext.py15
-rw-r--r--Lib/test/test_multibytecodec.py8
-rw-r--r--Lib/test/test_optparse.py14
-rw-r--r--Lib/test/test_robotparser.py4
-rw-r--r--Lib/test/test_support.py23
-rw-r--r--Lib/test/test_threading_local.py2
-rw-r--r--Lib/test/test_unicode.py2
-rw-r--r--Lib/test/test_unicode_file.py6
-rwxr-xr-xLib/test/test_wsgiref.py9
28 files changed, 74 insertions, 173 deletions
diff --git a/Lib/test/README b/Lib/test/README
index e805ee7..747d842 100644
--- a/Lib/test/README
+++ b/Lib/test/README
@@ -40,18 +40,22 @@ Java implementation of Beck's original SmallTalk test framework. Please
see the documentation of the unittest_ module for detailed information on
the interface and general guidelines on writing unittest-based tests.
-The test_support helper module provides two functions for use by
-unittest-based tests in the Python regression testing framework:
-
-- ``run_unittest()`` takes a number of ``unittest.TestCase`` derived classes as
- parameters and runs the tests defined in those classes.
-
-- ``run_suite()`` takes a populated ``TestSuite`` instance and runs the
- tests.
+The test_support helper module provides a function for use by
+unittest-based tests in the Python regression testing framework,
+``run_unittest()``. This is the primary way of running tests in the
+standard library. You can pass it any number of the following:
+
+- classes derived from or instances of ``unittest.TestCase`` or
+ ``unittest.TestSuite``. These will be handed off to unittest for
+ converting into a proper TestSuite instance.
+
+- a string; this must be a key in sys.modules. The module associated with
+ that string will be scanned by ``unittest.TestLoader.loadTestsFromModule``.
+ This is usually seen as ``test_support.run_unittest(__name__)`` in a test
+ module's ``test_main()`` function. This has the advantage of picking up
+ new tests automatically, without you having to add each new test case
+ manually.
-``run_suite()`` is preferred because unittest files typically grow multiple
-test classes, and you might as well be prepared.
-
All test methods in the Python regression framework have names that
start with "``test_``" and use lower-case names with words separated with
underscores.
@@ -96,11 +100,7 @@ looks like this (with minor variations)::
...etc...
def test_main():
- suite = unittest.TestSuite()
- suite.addTest(unittest.makeSuite(MyTestCase1))
- suite.addTest(unittest.makeSuite(MyTestCase2))
- ...add more suites...
- test_support.run_suite(suite)
+ test_support.run_unittest(__name__)
if __name__ == "__main__":
test_main()
diff --git a/Lib/test/test_base64.py b/Lib/test/test_base64.py
index 997a413..ff2c370 100644
--- a/Lib/test/test_base64.py
+++ b/Lib/test/test_base64.py
@@ -183,16 +183,8 @@ class BaseXYTestCase(unittest.TestCase):
-def suite():
- suite = unittest.TestSuite()
- suite.addTest(unittest.makeSuite(LegacyBase64TestCase))
- suite.addTest(unittest.makeSuite(BaseXYTestCase))
- return suite
-
-
def test_main():
- test_support.run_suite(suite())
-
+ test_support.run_unittest(__name__)
if __name__ == '__main__':
- unittest.main(defaultTest='suite')
+ test_main()
diff --git a/Lib/test/test_bsddb3.py b/Lib/test/test_bsddb3.py
index 8b0c50c..349a6b0 100644
--- a/Lib/test/test_bsddb3.py
+++ b/Lib/test/test_bsddb3.py
@@ -4,11 +4,11 @@ Run all test cases.
"""
import sys
import unittest
-from test.test_support import requires, verbose, run_suite, unlink
+from test.test_support import requires, verbose, run_unittest, unlink
# When running as a script instead of within the regrtest framework, skip the
# requires test, since it's obvious we want to run them.
-if __name__ <> '__main__':
+if __name__ != '__main__':
requires('bsddb')
verbose = False
@@ -58,9 +58,7 @@ def suite():
# For invocation through regrtest
def test_main():
- tests = suite()
- run_suite(tests)
-
+ run_unittest(suite())
# For invocation as a script
if __name__ == '__main__':
@@ -73,4 +71,4 @@ if __name__ == '__main__':
print 'python version: %s' % sys.version
print '-=' * 38
- unittest.main(defaultTest='suite')
+ test_main()
diff --git a/Lib/test/test_codecencodings_cn.py b/Lib/test/test_codecencodings_cn.py
index c558f1b..96b0d77 100644
--- a/Lib/test/test_codecencodings_cn.py
+++ b/Lib/test/test_codecencodings_cn.py
@@ -51,11 +51,7 @@ class Test_GB18030(test_multibytecodec_support.TestBase, unittest.TestCase):
has_iso10646 = True
def test_main():
- suite = unittest.TestSuite()
- suite.addTest(unittest.makeSuite(Test_GB2312))
- suite.addTest(unittest.makeSuite(Test_GBK))
- suite.addTest(unittest.makeSuite(Test_GB18030))
- test_support.run_suite(suite)
+ test_support.run_unittest(__name__)
if __name__ == "__main__":
test_main()
diff --git a/Lib/test/test_codecencodings_hk.py b/Lib/test/test_codecencodings_hk.py
index 1cd020f..b1c2606 100644
--- a/Lib/test/test_codecencodings_hk.py
+++ b/Lib/test/test_codecencodings_hk.py
@@ -21,9 +21,7 @@ class Test_Big5HKSCS(test_multibytecodec_support.TestBase, unittest.TestCase):
)
def test_main():
- suite = unittest.TestSuite()
- suite.addTest(unittest.makeSuite(Test_Big5HKSCS))
- test_support.run_suite(suite)
+ test_support.run_unittest(__name__)
if __name__ == "__main__":
test_main()
diff --git a/Lib/test/test_codecencodings_jp.py b/Lib/test/test_codecencodings_jp.py
index 558598a..5f81f41 100644
--- a/Lib/test/test_codecencodings_jp.py
+++ b/Lib/test/test_codecencodings_jp.py
@@ -99,13 +99,7 @@ class Test_SJISX0213(test_multibytecodec_support.TestBase, unittest.TestCase):
)
def test_main():
- suite = unittest.TestSuite()
- suite.addTest(unittest.makeSuite(Test_CP932))
- suite.addTest(unittest.makeSuite(Test_EUC_JISX0213))
- suite.addTest(unittest.makeSuite(Test_EUC_JP_COMPAT))
- suite.addTest(unittest.makeSuite(Test_SJIS_COMPAT))
- suite.addTest(unittest.makeSuite(Test_SJISX0213))
- test_support.run_suite(suite)
+ test_support.run_unittest(__name__)
if __name__ == "__main__":
test_main()
diff --git a/Lib/test/test_codecencodings_kr.py b/Lib/test/test_codecencodings_kr.py
index 8139f76..a30eaf9 100644
--- a/Lib/test/test_codecencodings_kr.py
+++ b/Lib/test/test_codecencodings_kr.py
@@ -45,11 +45,7 @@ class Test_JOHAB(test_multibytecodec_support.TestBase, unittest.TestCase):
)
def test_main():
- suite = unittest.TestSuite()
- suite.addTest(unittest.makeSuite(Test_CP949))
- suite.addTest(unittest.makeSuite(Test_EUCKR))
- suite.addTest(unittest.makeSuite(Test_JOHAB))
- test_support.run_suite(suite)
+ test_support.run_unittest(__name__)
if __name__ == "__main__":
test_main()
diff --git a/Lib/test/test_codecencodings_tw.py b/Lib/test/test_codecencodings_tw.py
index 7c59478..983d06f 100644
--- a/Lib/test/test_codecencodings_tw.py
+++ b/Lib/test/test_codecencodings_tw.py
@@ -21,9 +21,7 @@ class Test_Big5(test_multibytecodec_support.TestBase, unittest.TestCase):
)
def test_main():
- suite = unittest.TestSuite()
- suite.addTest(unittest.makeSuite(Test_Big5))
- test_support.run_suite(suite)
+ test_support.run_unittest(__name__)
if __name__ == "__main__":
test_main()
diff --git a/Lib/test/test_codecmaps_cn.py b/Lib/test/test_codecmaps_cn.py
index 8cbee76..75541ac 100644
--- a/Lib/test/test_codecmaps_cn.py
+++ b/Lib/test/test_codecmaps_cn.py
@@ -20,10 +20,7 @@ class TestGBKMap(test_multibytecodec_support.TestBase_Mapping,
'MICSFT/WINDOWS/CP936.TXT'
def test_main():
- suite = unittest.TestSuite()
- suite.addTest(unittest.makeSuite(TestGB2312Map))
- suite.addTest(unittest.makeSuite(TestGBKMap))
- test_support.run_suite(suite)
+ test_support.run_unittest(__name__)
if __name__ == "__main__":
test_main()
diff --git a/Lib/test/test_codecmaps_hk.py b/Lib/test/test_codecmaps_hk.py
index e7f7b96..1068d0b 100644
--- a/Lib/test/test_codecmaps_hk.py
+++ b/Lib/test/test_codecmaps_hk.py
@@ -14,9 +14,7 @@ class TestBig5HKSCSMap(test_multibytecodec_support.TestBase_Mapping,
mapfileurl = 'http://people.freebsd.org/~perky/i18n/BIG5HKSCS.TXT'
def test_main():
- suite = unittest.TestSuite()
- suite.addTest(unittest.makeSuite(TestBig5HKSCSMap))
- test_support.run_suite(suite)
+ test_support.run_unittest(__name__)
if __name__ == "__main__":
test_main()
diff --git a/Lib/test/test_codecmaps_jp.py b/Lib/test/test_codecmaps_jp.py
index 08052d4..5466a98 100644
--- a/Lib/test/test_codecmaps_jp.py
+++ b/Lib/test/test_codecmaps_jp.py
@@ -61,13 +61,7 @@ class TestSJISX0213Map(test_multibytecodec_support.TestBase_Mapping,
def test_main():
- suite = unittest.TestSuite()
- suite.addTest(unittest.makeSuite(TestCP932Map))
- suite.addTest(unittest.makeSuite(TestEUCJPCOMPATMap))
- suite.addTest(unittest.makeSuite(TestSJISCOMPATMap))
- suite.addTest(unittest.makeSuite(TestEUCJISX0213Map))
- suite.addTest(unittest.makeSuite(TestSJISX0213Map))
- test_support.run_suite(suite)
+ test_support.run_unittest(__name__)
if __name__ == "__main__":
test_main()
diff --git a/Lib/test/test_codecmaps_kr.py b/Lib/test/test_codecmaps_kr.py
index 7484a66..1b350b9 100644
--- a/Lib/test/test_codecmaps_kr.py
+++ b/Lib/test/test_codecmaps_kr.py
@@ -34,11 +34,7 @@ class TestJOHABMap(test_multibytecodec_support.TestBase_Mapping,
pass_dectest = [('\\', u'\u20a9')]
def test_main():
- suite = unittest.TestSuite()
- suite.addTest(unittest.makeSuite(TestCP949Map))
- suite.addTest(unittest.makeSuite(TestEUCKRMap))
- suite.addTest(unittest.makeSuite(TestJOHABMap))
- test_support.run_suite(suite)
+ test_support.run_unittest(__name__)
if __name__ == "__main__":
test_main()
diff --git a/Lib/test/test_codecmaps_tw.py b/Lib/test/test_codecmaps_tw.py
index 0b195f4..143ae23 100644
--- a/Lib/test/test_codecmaps_tw.py
+++ b/Lib/test/test_codecmaps_tw.py
@@ -25,10 +25,7 @@ class TestCP950Map(test_multibytecodec_support.TestBase_Mapping,
]
def test_main():
- suite = unittest.TestSuite()
- suite.addTest(unittest.makeSuite(TestBIG5Map))
- suite.addTest(unittest.makeSuite(TestCP950Map))
- test_support.run_suite(suite)
+ test_support.run_unittest(__name__)
if __name__ == "__main__":
test_main()
diff --git a/Lib/test/test_contextlib.py b/Lib/test/test_contextlib.py
index 747785d..898bcf2 100644
--- a/Lib/test/test_contextlib.py
+++ b/Lib/test/test_contextlib.py
@@ -9,7 +9,7 @@ import tempfile
import unittest
import threading
from contextlib import * # Tests __all__
-from test.test_support import run_suite
+from test import test_support
class ContextManagerTestCase(unittest.TestCase):
@@ -332,9 +332,7 @@ class LockContextTestCase(unittest.TestCase):
# This is needed to make the test actually run under regrtest.py!
def test_main():
- run_suite(
- unittest.defaultTestLoader.loadTestsFromModule(sys.modules[__name__])
- )
+ test_support.run_unittest(__name__)
if __name__ == "__main__":
test_main()
diff --git a/Lib/test/test_ctypes.py b/Lib/test/test_ctypes.py
index fd2032b..7a81ab4 100644
--- a/Lib/test/test_ctypes.py
+++ b/Lib/test/test_ctypes.py
@@ -1,12 +1,12 @@
import unittest
-from test.test_support import run_suite
+from test.test_support import run_unittest
import ctypes.test
def test_main():
skipped, testcases = ctypes.test.get_tests(ctypes.test, "test_*.py", verbosity=0)
suites = [unittest.makeSuite(t) for t in testcases]
- run_suite(unittest.TestSuite(suites))
+ run_unittest(unittest.TestSuite(suites))
if __name__ == "__main__":
test_main()
diff --git a/Lib/test/test_datetime.py b/Lib/test/test_datetime.py
index fe9e3ab..72391af 100644
--- a/Lib/test/test_datetime.py
+++ b/Lib/test/test_datetime.py
@@ -128,7 +128,7 @@ class TestTZInfo(unittest.TestCase):
# Base clase for testing a particular aspect of timedelta, time, date and
# datetime comparisons.
-class HarmlessMixedComparison(unittest.TestCase):
+class HarmlessMixedComparison:
# Test that __eq__ and __ne__ don't complain for mixed-type comparisons.
# Subclasses must define 'theclass', and theclass(1, 1, 1) must be a
@@ -167,7 +167,7 @@ class HarmlessMixedComparison(unittest.TestCase):
#############################################################################
# timedelta tests
-class TestTimeDelta(HarmlessMixedComparison):
+class TestTimeDelta(HarmlessMixedComparison, unittest.TestCase):
theclass = timedelta
@@ -514,7 +514,7 @@ class TestDateOnly(unittest.TestCase):
class SubclassDate(date):
sub_var = 1
-class TestDate(HarmlessMixedComparison):
+class TestDate(HarmlessMixedComparison, unittest.TestCase):
# Tests here should pass for both dates and datetimes, except for a
# few tests that TestDateTime overrides.
@@ -1596,7 +1596,7 @@ class TestDateTime(TestDate):
class SubclassTime(time):
sub_var = 1
-class TestTime(HarmlessMixedComparison):
+class TestTime(HarmlessMixedComparison, unittest.TestCase):
theclass = time
@@ -1879,7 +1879,7 @@ class TestTime(HarmlessMixedComparison):
# A mixin for classes with a tzinfo= argument. Subclasses must define
# theclass as a class atribute, and theclass(1, 1, 1, tzinfo=whatever)
# must be legit (which is true for time and datetime).
-class TZInfoBase(unittest.TestCase):
+class TZInfoBase:
def test_argument_passing(self):
cls = self.theclass
@@ -2039,7 +2039,7 @@ class TZInfoBase(unittest.TestCase):
# Testing time objects with a non-None tzinfo.
-class TestTimeTZ(TestTime, TZInfoBase):
+class TestTimeTZ(TestTime, TZInfoBase, unittest.TestCase):
theclass = time
def test_empty(self):
@@ -2287,7 +2287,7 @@ class TestTimeTZ(TestTime, TZInfoBase):
# Testing datetime objects with a non-None tzinfo.
-class TestDateTimeTZ(TestDateTime, TZInfoBase):
+class TestDateTimeTZ(TestDateTime, TZInfoBase, unittest.TestCase):
theclass = datetime
def test_trivial(self):
@@ -3248,31 +3248,13 @@ class Oddballs(unittest.TestCase):
self.assertEqual(as_datetime, datetime_sc)
self.assertEqual(datetime_sc, as_datetime)
-def test_suite():
- allsuites = [unittest.makeSuite(klass, 'test')
- for klass in (TestModule,
- TestTZInfo,
- TestTimeDelta,
- TestDateOnly,
- TestDate,
- TestDateTime,
- TestTime,
- TestTimeTZ,
- TestDateTimeTZ,
- TestTimezoneConversions,
- Oddballs,
- )
- ]
- return unittest.TestSuite(allsuites)
-
def test_main():
import gc
import sys
- thesuite = test_suite()
lastrc = None
while True:
- test_support.run_suite(thesuite)
+ test_support.run_unittest(__name__)
if 1: # change to 0, under a debug build, for some leak detection
break
gc.collect()
diff --git a/Lib/test/test_email.py b/Lib/test/test_email.py
index de0eee3..f609968 100644
--- a/Lib/test/test_email.py
+++ b/Lib/test/test_email.py
@@ -4,10 +4,10 @@
import unittest
# The specific tests now live in Lib/email/test
from email.test.test_email import suite
-from test.test_support import run_suite
+from test import test_support
def test_main():
- run_suite(suite())
+ test_support.run_unittest(suite())
if __name__ == '__main__':
test_main()
diff --git a/Lib/test/test_email_codecs.py b/Lib/test/test_email_codecs.py
index c550a6f..8951f81 100644
--- a/Lib/test/test_email_codecs.py
+++ b/Lib/test/test_email_codecs.py
@@ -9,7 +9,7 @@ from test import test_support
def test_main():
suite = test_email_codecs.suite()
suite.addTest(test_email_codecs_renamed.suite())
- test_support.run_suite(suite)
+ test_support.run_unittest(suite)
if __name__ == '__main__':
test_main()
diff --git a/Lib/test/test_email_renamed.py b/Lib/test/test_email_renamed.py
index c3af598..163e791 100644
--- a/Lib/test/test_email_renamed.py
+++ b/Lib/test/test_email_renamed.py
@@ -4,10 +4,10 @@
import unittest
# The specific tests now live in Lib/email/test
from email.test.test_email_renamed import suite
-from test.test_support import run_suite
+from test import test_support
def test_main():
- run_suite(suite())
+ test_support.run_unittest(suite())
if __name__ == '__main__':
test_main()
diff --git a/Lib/test/test_gettext.py b/Lib/test/test_gettext.py
index 76253de..ab6bc9a 100644
--- a/Lib/test/test_gettext.py
+++ b/Lib/test/test_gettext.py
@@ -4,7 +4,7 @@ import shutil
import gettext
import unittest
-from test.test_support import run_suite
+from test import test_support
# TODO:
@@ -336,19 +336,8 @@ class WeirdMetadataTest(GettextBaseTest):
'John Doe <jdoe@example.com>\nJane Foobar <jfoobar@example.com>')
-def suite():
- suite = unittest.TestSuite()
- suite.addTest(unittest.makeSuite(GettextTestCase1))
- suite.addTest(unittest.makeSuite(GettextTestCase2))
- suite.addTest(unittest.makeSuite(PluralFormsTestCase))
- suite.addTest(unittest.makeSuite(UnicodeTranslationsTest))
- suite.addTest(unittest.makeSuite(WeirdMetadataTest))
- return suite
-
-
def test_main():
- run_suite(suite())
-
+ test_support.run_unittest(__name__)
if __name__ == '__main__':
test_main()
diff --git a/Lib/test/test_multibytecodec.py b/Lib/test/test_multibytecodec.py
index a8666d3..de27339 100644
--- a/Lib/test/test_multibytecodec.py
+++ b/Lib/test/test_multibytecodec.py
@@ -219,13 +219,7 @@ class Test_ISO2022(unittest.TestCase):
myunichr(x).encode('iso_2022_jp', 'ignore')
def test_main():
- suite = unittest.TestSuite()
- suite.addTest(unittest.makeSuite(Test_MultibyteCodec))
- suite.addTest(unittest.makeSuite(Test_IncrementalEncoder))
- suite.addTest(unittest.makeSuite(Test_IncrementalDecoder))
- suite.addTest(unittest.makeSuite(Test_StreamWriter))
- suite.addTest(unittest.makeSuite(Test_ISO2022))
- test_support.run_suite(suite)
+ test_support.run_unittest(__name__)
if __name__ == "__main__":
test_main()
diff --git a/Lib/test/test_optparse.py b/Lib/test/test_optparse.py
index 9b52659..38d5207 100644
--- a/Lib/test/test_optparse.py
+++ b/Lib/test/test_optparse.py
@@ -1631,18 +1631,8 @@ class TestParseNumber(BaseTest):
"option -l: invalid long integer value: '0x12x'")
-def _testclasses():
- mod = sys.modules[__name__]
- return [getattr(mod, name) for name in dir(mod) if name.startswith('Test')]
-
-def suite():
- suite = unittest.TestSuite()
- for testclass in _testclasses():
- suite.addTest(unittest.makeSuite(testclass))
- return suite
-
def test_main():
- test_support.run_suite(suite())
+ test_support.run_unittest(__name__)
if __name__ == '__main__':
- unittest.main()
+ test_main()
diff --git a/Lib/test/test_robotparser.py b/Lib/test/test_robotparser.py
index 6a23b22..666d00a 100644
--- a/Lib/test/test_robotparser.py
+++ b/Lib/test/test_robotparser.py
@@ -135,8 +135,8 @@ bad = [] # Bug report says "/" should be denied, but that is not in the RFC
RobotTest(7, doc, good, bad)
def test_main():
- test_support.run_suite(tests)
+ test_support.run_unittest(tests)
if __name__=='__main__':
test_support.Verbose = 1
- test_support.run_suite(tests)
+ test_main()
diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py
index 7e24395..f185dab 100644
--- a/Lib/test/test_support.py
+++ b/Lib/test/test_support.py
@@ -8,6 +8,7 @@ import errno
import socket
import sys
import warnings
+import types
class Error(Exception):
"""Base class for regression test exceptions."""
@@ -519,7 +520,7 @@ class BasicTestRunner:
return result
-def run_suite(suite, testclass=None):
+def _run_suite(suite):
"""Run tests from a unittest.TestSuite-derived class."""
if verbose:
runner = unittest.TextTestRunner(sys.stdout, verbosity=2)
@@ -533,28 +534,26 @@ def run_suite(suite, testclass=None):
elif len(result.failures) == 1 and not result.errors:
err = result.failures[0][1]
else:
- if testclass is None:
- msg = "errors occurred; run in verbose mode for details"
- else:
- msg = "errors occurred in %s.%s" \
- % (testclass.__module__, testclass.__name__)
+ msg = "errors occurred; run in verbose mode for details"
raise TestFailed(msg)
raise TestFailed(err)
def run_unittest(*classes):
"""Run tests from unittest.TestCase-derived classes."""
+ valid_types = (unittest.TestSuite, unittest.TestCase)
suite = unittest.TestSuite()
for cls in classes:
- if isinstance(cls, (unittest.TestSuite, unittest.TestCase)):
+ if isinstance(cls, str):
+ if cls in sys.modules:
+ suite.addTest(unittest.findTestCases(sys.modules[cls]))
+ else:
+ raise ValueError("str arguments must be keys in sys.modules")
+ elif isinstance(cls, valid_types):
suite.addTest(cls)
else:
suite.addTest(unittest.makeSuite(cls))
- if len(classes)==1:
- testclass = classes[0]
- else:
- testclass = None
- run_suite(suite, testclass)
+ _run_suite(suite)
#=======================================================================
diff --git a/Lib/test/test_threading_local.py b/Lib/test/test_threading_local.py
index 56fbedd..0aaedbc 100644
--- a/Lib/test/test_threading_local.py
+++ b/Lib/test/test_threading_local.py
@@ -20,7 +20,7 @@ def test_main():
setUp=setUp, tearDown=tearDown)
)
- test_support.run_suite(suite)
+ test_support.run_unittest(suite)
if __name__ == '__main__':
test_main()
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py
index 1bc15ae..5ad54bf 100644
--- a/Lib/test/test_unicode.py
+++ b/Lib/test/test_unicode.py
@@ -822,7 +822,7 @@ class UnicodeTest(
def test_main():
- test_support.run_unittest(UnicodeTest)
+ test_support.run_unittest(__name__)
if __name__ == "__main__":
test_main()
diff --git a/Lib/test/test_unicode_file.py b/Lib/test/test_unicode_file.py
index 6443efd..ee2960a 100644
--- a/Lib/test/test_unicode_file.py
+++ b/Lib/test/test_unicode_file.py
@@ -5,7 +5,7 @@ import os, glob, time, shutil
import unicodedata
import unittest
-from test.test_support import run_suite, TestSkipped, TESTFN_UNICODE
+from test.test_support import run_unittest, TestSkipped, TESTFN_UNICODE
from test.test_support import TESTFN_ENCODING, TESTFN_UNICODE_UNENCODEABLE
try:
TESTFN_ENCODED = TESTFN_UNICODE.encode(TESTFN_ENCODING)
@@ -205,9 +205,7 @@ class TestUnicodeFiles(unittest.TestCase):
False)
def test_main():
- suite = unittest.TestSuite()
- suite.addTest(unittest.makeSuite(TestUnicodeFiles))
- run_suite(suite)
+ run_unittest(__name__)
if __name__ == "__main__":
test_main()
diff --git a/Lib/test/test_wsgiref.py b/Lib/test/test_wsgiref.py
index 1ec271b..b6d994b 100755
--- a/Lib/test/test_wsgiref.py
+++ b/Lib/test/test_wsgiref.py
@@ -1,5 +1,5 @@
from __future__ import nested_scopes # Backward compat for 2.1
-from unittest import TestSuite, TestCase, makeSuite
+from unittest import TestCase
from wsgiref.util import setup_testing_defaults
from wsgiref.headers import Headers
from wsgiref.handlers import BaseHandler, BaseCGIHandler
@@ -11,6 +11,7 @@ from StringIO import StringIO
from SocketServer import BaseServer
import re, sys
+from test import test_support
class MockServer(WSGIServer):
"""Non-socket HTTP server"""
@@ -575,11 +576,7 @@ class HandlerTests(TestCase):
# This epilogue is needed for compatibility with the Python 2.5 regrtest module
def test_main():
- import unittest
- from test.test_support import run_suite
- run_suite(
- unittest.defaultTestLoader.loadTestsFromModule(sys.modules[__name__])
- )
+ test_support.run_unittest(__name__)
if __name__ == "__main__":
test_main()