Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions bpython/test/test_curtsies_repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -292,6 +298,20 @@ def setUp(self):
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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please document why invalidate_caches is called here?


def tearDown(self):
sys.dont_write_bytecode = self.dont_write_bytecode

Expand Down