Commit ceffda82 authored by Brett Cannon's avatar Brett Cannon

Issue #14599: Make test_reprlib robust against import cache race

conditions when regrtest is run with its -j option.
parent de10bf4f
...@@ -213,6 +213,8 @@ class LongReprTest(unittest.TestCase): ...@@ -213,6 +213,8 @@ class LongReprTest(unittest.TestCase):
# Remember where we are # Remember where we are
self.here = os.getcwd() self.here = os.getcwd()
sys.path.insert(0, self.here) sys.path.insert(0, self.here)
# When regrtest is run with its -j option, this command alone is not
# enough.
importlib.invalidate_caches() importlib.invalidate_caches()
def tearDown(self): def tearDown(self):
...@@ -233,6 +235,7 @@ class LongReprTest(unittest.TestCase): ...@@ -233,6 +235,7 @@ class LongReprTest(unittest.TestCase):
def test_module(self): def test_module(self):
eq = self.assertEqual eq = self.assertEqual
create_empty_file(os.path.join(self.subpkgname, self.pkgname + '.py')) create_empty_file(os.path.join(self.subpkgname, self.pkgname + '.py'))
importlib.invalidate_caches()
from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import areallylongpackageandmodulenametotestreprtruncation from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import areallylongpackageandmodulenametotestreprtruncation
eq(repr(areallylongpackageandmodulenametotestreprtruncation), eq(repr(areallylongpackageandmodulenametotestreprtruncation),
"<module %r from %r>" % (areallylongpackageandmodulenametotestreprtruncation.__name__, areallylongpackageandmodulenametotestreprtruncation.__file__)) "<module %r from %r>" % (areallylongpackageandmodulenametotestreprtruncation.__name__, areallylongpackageandmodulenametotestreprtruncation.__file__))
...@@ -244,6 +247,7 @@ class LongReprTest(unittest.TestCase): ...@@ -244,6 +247,7 @@ class LongReprTest(unittest.TestCase):
class foo(object): class foo(object):
pass pass
''') ''')
importlib.invalidate_caches()
from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import foo from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import foo
eq(repr(foo.foo), eq(repr(foo.foo),
"<class '%s.foo'>" % foo.__name__) "<class '%s.foo'>" % foo.__name__)
...@@ -258,6 +262,7 @@ class foo(object): ...@@ -258,6 +262,7 @@ class foo(object):
class bar: class bar:
pass pass
''') ''')
importlib.invalidate_caches()
from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import bar from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import bar
# Module name may be prefixed with "test.", depending on how run. # Module name may be prefixed with "test.", depending on how run.
self.assertEqual(repr(bar.bar), "<class '%s.bar'>" % bar.__name__) self.assertEqual(repr(bar.bar), "<class '%s.bar'>" % bar.__name__)
...@@ -267,6 +272,7 @@ class bar: ...@@ -267,6 +272,7 @@ class bar:
class baz: class baz:
pass pass
''') ''')
importlib.invalidate_caches()
from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import baz from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import baz
ibaz = baz.baz() ibaz = baz.baz()
self.assertTrue(repr(ibaz).startswith( self.assertTrue(repr(ibaz).startswith(
...@@ -278,6 +284,7 @@ class baz: ...@@ -278,6 +284,7 @@ class baz:
class aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: class aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:
def amethod(self): pass def amethod(self): pass
''') ''')
importlib.invalidate_caches()
from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import qux from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import qux
# Unbound methods first # Unbound methods first
r = repr(qux.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.amethod) r = repr(qux.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.amethod)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment