diff options
author | Amaury Forgeot d'Arc <amauryfa@gmail.com> | 2008-04-18 23:31:33 +0000 |
---|---|---|
committer | Amaury Forgeot d'Arc <amauryfa@gmail.com> | 2008-04-18 23:31:33 +0000 |
commit | 607bff1ebe81e869697e228322da4c308e8753a5 (patch) | |
tree | ab9126adaba09e9c1cd436b1ca76c5ac3d67eb3c /Lib/test | |
parent | 6f34109384f3a78d5f4f8bdd418a89caca19631e (diff) | |
download | cpython-git-607bff1ebe81e869697e228322da4c308e8753a5.tar.gz |
Some tests did not pass on repeated calls (regrtest -R::)
Perform additional cleanup, mostly deleting from sys.modules, or clearing the warnings registry.
Diffstat (limited to 'Lib/test')
-rwxr-xr-x | Lib/test/regrtest.py | 5 | ||||
-rw-r--r-- | Lib/test/test_frozen.py | 4 | ||||
-rw-r--r-- | Lib/test/test_pkg.py | 12 | ||||
-rw-r--r-- | Lib/test/test_pkgutil.py | 4 | ||||
-rwxr-xr-x | Lib/test/test_profile.py | 5 | ||||
-rw-r--r-- | Lib/test/test_structmembers.py | 6 | ||||
-rw-r--r-- | Lib/test/test_warnings.py | 2 |
7 files changed, 29 insertions, 9 deletions
diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py index 7ea8668d94..b092bd93b7 100755 --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -683,6 +683,11 @@ def dash_R_cleanup(fs, ps, pic, abcs): import struct, filecmp from distutils.dir_util import _path_created + # Clear the warnings registry, so they can be displayed again + for mod in sys.modules.values(): + if hasattr(mod, '__warningregistry__'): + del mod.__warningregistry__ + # Restore some original values. warnings.filters[:] = fs copy_reg.dispatch_table.clear() diff --git a/Lib/test/test_frozen.py b/Lib/test/test_frozen.py index e981fb3ddb..4835e475f8 100644 --- a/Lib/test/test_frozen.py +++ b/Lib/test/test_frozen.py @@ -35,6 +35,10 @@ class FrozenTests(unittest.TestCase): self.assertEquals(stdout.getvalue(), 'Hello world...\nHello world...\nHello world...\n') + del sys.modules['__hello__'] + del sys.modules['__phello__'] + del sys.modules['__phello__.spam'] + def test_main(): run_unittest(FrozenTests) diff --git a/Lib/test/test_pkg.py b/Lib/test/test_pkg.py index 4fa367f560..3a954ca366 100644 --- a/Lib/test/test_pkg.py +++ b/Lib/test/test_pkg.py @@ -46,12 +46,20 @@ class Test(unittest.TestCase): def setUp(self): self.root = None + self.pkgname = None self.syspath = list(sys.path) def tearDown(self): sys.path[:] = self.syspath cleanout(self.root) + # delete all modules concerning the tested hiearchy + if self.pkgname: + modules = [name for name in sys.modules + if self.pkgname in name.split('.')] + for name in modules: + del sys.modules[name] + def run_code(self, code): exec(textwrap.dedent(code), globals(), {"self": self}) @@ -74,6 +82,8 @@ class Test(unittest.TestCase): f.write('\n') f.close() self.root = root + # package name is the name of the first item + self.pkgname = descr[0][0] def test_1(self): hier = [("t1", None), ("t1 __init__"+os.extsep+"py", "")] @@ -223,8 +233,8 @@ class Test(unittest.TestCase): def test_7(self): hier = [ - ("t7"+os.extsep+"py", ""), ("t7", None), + ("t7"+os.extsep+"py", ""), ("t7 __init__"+os.extsep+"py", ""), ("t7 sub"+os.extsep+"py", "raise RuntimeError('Shouldnt load sub.py')"), diff --git a/Lib/test/test_pkgutil.py b/Lib/test/test_pkgutil.py index 4381f911bb..a14f09187a 100644 --- a/Lib/test/test_pkgutil.py +++ b/Lib/test/test_pkgutil.py @@ -48,6 +48,8 @@ class PkgutilTests(unittest.TestCase): res2 = pkgutil.get_data(pkg, 'sub/res.txt') self.assertEqual(res2, RESOURCE_DATA) + del sys.modules[pkg] + def test_getdata_zipfile(self): zip = 'test_getdata_zipfile.zip' pkg = 'test_getdata_zipfile' @@ -74,6 +76,8 @@ class PkgutilTests(unittest.TestCase): self.assertEqual(res2, RESOURCE_DATA) del sys.path[0] + del sys.modules[pkg] + class PkgutilPEP302Tests(unittest.TestCase): class MyTestLoader(object): diff --git a/Lib/test/test_profile.py b/Lib/test/test_profile.py index c8281c3436..0bd2530cf2 100755 --- a/Lib/test/test_profile.py +++ b/Lib/test/test_profile.py @@ -21,8 +21,9 @@ class ProfileTest(unittest.TestCase): def do_profiling(cls): results = [] prof = cls.profilerclass(timer, 0.001) + start_timer = timer() prof.runctx("testfunc()", globals(), locals()) - results.append(timer()) + results.append(timer() - start_timer) for methodname in cls.methodnames: s = StringIO() stats = pstats.Stats(prof, stream=s) @@ -33,7 +34,7 @@ class ProfileTest(unittest.TestCase): def test_cprofile(self): results = self.do_profiling() - self.assertEqual(results[0], 43000) + self.assertEqual(results[0], 1000) for i, method in enumerate(self.methodnames): self.assertEqual(results[i+1], self.expected_output[method], "Stats.%s output for %s doesn't fit expectation!" % diff --git a/Lib/test/test_structmembers.py b/Lib/test/test_structmembers.py index a59cfa952f..6c1a947fe3 100644 --- a/Lib/test/test_structmembers.py +++ b/Lib/test/test_structmembers.py @@ -101,12 +101,6 @@ class TestWarnings(unittest.TestCase): def test_main(verbose=None): - # Obscure hack so that this test passes after reloads or repeated calls - # to test_main (regrtest -R). - if '__warningregistry__' in globals(): - del globals()['__warningregistry__'] - if hasattr(sys, '__warningregistry__'): - del sys.__warningregistry__ test_support.run_unittest(__name__) if __name__ == "__main__": diff --git a/Lib/test/test_warnings.py b/Lib/test/test_warnings.py index fb6aabbd35..9fca080247 100644 --- a/Lib/test/test_warnings.py +++ b/Lib/test/test_warnings.py @@ -391,6 +391,8 @@ class PyWarningsDisplayTests(BaseTest, WarningsDisplayTests): def test_main(): + py_warnings.onceregistry.clear() + c_warnings.onceregistry.clear() test_support.run_unittest(CFilterTests, PyFilterTests, CWarnTests, |