From a108ee1b57426f53886664c808d037f09cd0f7b1 Mon Sep 17 00:00:00 2001 From: Thomas Ballinger Date: Thu, 3 Dec 2015 11:22:43 -0500 Subject: [PATCH 1/2] fix run order-dependant test failure --- bpython/test/test_curtsies_repl.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bpython/test/test_curtsies_repl.py b/bpython/test/test_curtsies_repl.py index 1e405bffc..8ff3b0908 100644 --- a/bpython/test/test_curtsies_repl.py +++ b/bpython/test/test_curtsies_repl.py @@ -20,6 +20,12 @@ from bpython.test import (FixLanguageTestCase as TestCase, MagicIterMock, mock, builtin_target, unittest) +if py3: + from importlib import invalidate_caches +else: + def invalidate_caches(): + """Does not exist before Python 3.3""" + def setup_config(conf): config_struct = config.Struct() @@ -291,6 +297,7 @@ def setUp(self): self.open = partial(io.open, mode='wt', encoding='utf-8') self.dont_write_bytecode = sys.dont_write_bytecode sys.dont_write_bytecode = True + invalidate_caches() def tearDown(self): sys.dont_write_bytecode = self.dont_write_bytecode From 9966986583cf4de5201b34943332922f5b80bcd5 Mon Sep 17 00:00:00 2001 From: Thomas Ballinger Date: Sun, 6 Dec 2015 16:18:54 -0500 Subject: [PATCH 2/2] Document why invalidate_caches needed --- bpython/test/test_curtsies_repl.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/bpython/test/test_curtsies_repl.py b/bpython/test/test_curtsies_repl.py index 8ff3b0908..1d408c5e6 100644 --- a/bpython/test/test_curtsies_repl.py +++ b/bpython/test/test_curtsies_repl.py @@ -297,6 +297,19 @@ def setUp(self): self.open = partial(io.open, mode='wt', encoding='utf-8') self.dont_write_bytecode = sys.dont_write_bytecode sys.dont_write_bytecode = True + + # Because these tests create Python source files at runtime, + # it's possible for the importlib.machinery.FileFinder for + # a directory to have an outdated cache in the following situation: + # * a module in that directory is imported, + # * then a new module is created in that directory, + # * then that new module is imported. + # + # invalidate_cache() is used to prevent this. + # + # see https://docs.python.org/3/library/importlib.html + # sections #importlib.machinery.FileFinder and + # #importlib.invalidate_caches invalidate_caches() def tearDown(self):