cache_dir = os.path.join(fn_pypath.dirname, "__pycache__")
- except py.error.EACCES:
- state.trace("read only directory: %r" % (fn_pypath.dirname,))
- except py.error.EEXIST:
- state.trace("failure to create directory: %r" % (
+ e = sys.exc_info().errno
+ # Either the __pycache__ directory already exists (the
+ # common case) or it's blocked by a non-dir node. In the
+ # latter case, we'll ignore it in _write_pyc.
+ elif e == errno.ENOTDIR:
+ # One of the path components was not a directory, likely
+ # because we're in a zip file.
+ elif e == errno.EACCES:
+ state.trace("read only directory: %r" % (fn_pypath.dirname,))
cache_name = fn_pypath.basename[:-3] + "." + PYTEST_TAG + ".pyc"
pyc = os.path.join(cache_dir, cache_name)
# Notice that even if we're in a read-only directory, I'm going to check
# little reason deviate, and I hope sometime to be able to use
# imp.load_compiled to load them. (See the comment in load_module above.)
mtime = int(source_path.mtime())
+ if sys.exc_info().errno == errno.ENOTDIR:
+ # This happens when we get a EEXIST in find_module creating the
+ # __pycache__ directory and __pycache__ is by some non-dir node.
def _rewrite_test(state, fn):
"""Try to read and rewrite *fn* and return the code object."""
# When not on windows, assume rename is atomic. Dump the code object
# into a file specific to this process and atomically replace it.
proc_pyc = pyc + "." + str(os.getpid())
- _write_pyc(co, fn, proc_pyc)
- os.rename(proc_pyc, pyc)
+ if _write_pyc(co, fn, proc_pyc):
+ os.rename(proc_pyc, pyc)
def _read_pyc(source, pyc):