diff --git a/_pytest/assertion/rewrite.py b/_pytest/assertion/rewrite.py index 662a7ccfd..32d34acf7 100644 --- a/_pytest/assertion/rewrite.py +++ b/_pytest/assertion/rewrite.py @@ -15,6 +15,12 @@ import py from _pytest.assertion import util +# Windows gives ENOENT in places *nix gives ENOTDIR. +if sys.platform.startswith("win"): + PATH_COMPONENT_NOT_DIR = errno.ENOENT +else: + PATH_COMPONENT_NOT_DIR = errno.ENOTDIR + # py.test caches rewritten pycs in __pycache__. if hasattr(imp, "get_tag"): PYTEST_TAG = imp.get_tag() + "-PYTEST" @@ -106,8 +112,7 @@ class AssertionRewritingHook(object): # common case) or it's blocked by a non-dir node. In the # latter case, we'll ignore it in _write_pyc. pass - elif (e == errno.ENOTDIR or - sys.platform == "win32" and e == errno.ENOENT): + elif e == PATH_COMPONENT_NOT_DIR: # One of the path components was not a directory, likely # because we're in a zip file. write = False @@ -160,8 +165,7 @@ def _write_pyc(co, source_path, pyc): fp = open(pyc, "wb") except IOError: err = sys.exc_info()[1].errno - if (err == errno.ENOTDIR or - sys.platform == "win32" and err == errno.ENOENT): + if err == PATH_COMPONENT_NOT_DIR: # This happens when we get a EEXIST in find_module creating the # __pycache__ directory and __pycache__ is by some non-dir node. return False