From 92f9eb2f99d1a13cd960834884f0186139e433cf Mon Sep 17 00:00:00 2001 From: "Michael J. Sullivan" Date: Wed, 21 Nov 2018 12:01:35 -0800 Subject: [PATCH] Fix some intermittent test failures due to failure to import plugin While trying to test mypy_mypyc wheels in travis on OS X, I pretty consistently got failures trying to import a plugin module. I had trouble reproducing it anywhere else, but the issue turned out to be a cousin of the dreaded stubgen flake (#4811), where caching in importlib causes a file to be missed even though it is present now. Here we solve it by using absolute paths in the `load_plugins` manipulations of sys.path. --- mypy/build.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mypy/build.py b/mypy/build.py index 0d3eb901793cf..9c18f5c93bf92 100644 --- a/mypy/build.py +++ b/mypy/build.py @@ -341,7 +341,10 @@ def plugin_error(message: str) -> None: plugin_path = os.path.join(os.path.dirname(options.config_file), plugin_path) if not os.path.isfile(plugin_path): plugin_error("Can't find plugin '{}'".format(plugin_path)) - plugin_dir = os.path.dirname(plugin_path) + # Use an absolute path to avoid populating the cache entry + # for 'tmp' during tests, since it will be different in + # different tests. + plugin_dir = os.path.abspath(os.path.dirname(plugin_path)) fnam = os.path.basename(plugin_path) module_name = fnam[:-3] sys.path.insert(0, plugin_dir)