diff --git a/_pytest/assertion/rewrite.py b/_pytest/assertion/rewrite.py index 7e600d2c9..0a8320e2f 100644 --- a/_pytest/assertion/rewrite.py +++ b/_pytest/assertion/rewrite.py @@ -158,7 +158,9 @@ def _write_pyc(co, source_path, pyc): try: fp = open(pyc, "wb") except IOError: - if sys.exc_info()[1].errno == errno.ENOTDIR: + err = sys.exc_info()[1].errno + if (err == errno.ENOTDIR or + sys.platform == "win32" and err == errno.ENOENT): # This happens when we get a EEXIST in find_module creating the # __pycache__ directory and __pycache__ is by some non-dir node. return False