From 9ccd52d538499b9f77f92ca02b85aae0d1705cd1 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Thu, 1 Aug 2013 15:43:42 +0200 Subject: [PATCH] fix issue305 - ignore any problems in writing a pyc file, but print out a trace. --- CHANGELOG | 2 ++ _pytest/assertion/rewrite.py | 20 ++++++++------------ testing/test_assertrewrite.py | 20 ++++++++++++++++++++ 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 354ca0bba..eae21a394 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -6,6 +6,8 @@ Changes between 2.3.5 and 2.4.DEV - remove implicit distribute_setup support from setup.py. +- fix issue305: ignore any problems when writing pyc files. + - integrate tab-completion on options through use of "argcomplete". Thanks Anthon van der Neut for the PR. diff --git a/_pytest/assertion/rewrite.py b/_pytest/assertion/rewrite.py index 52c846ee7..779344b02 100644 --- a/_pytest/assertion/rewrite.py +++ b/_pytest/assertion/rewrite.py @@ -156,7 +156,7 @@ class AssertionRewritingHook(object): raise return sys.modules[name] -def _write_pyc(co, source_path, pyc): +def _write_pyc(state, co, source_path, pyc): # Technically, we don't have to have the same pyc format as # (C)Python, since these "pycs" should never be seen by builtin # import. However, there's little reason deviate, and I hope @@ -167,15 +167,11 @@ def _write_pyc(co, source_path, pyc): fp = open(pyc, "wb") except IOError: err = sys.exc_info()[1].errno - if err in [errno.ENOENT, errno.ENOTDIR]: - # This happens when we get a EEXIST in find_module creating the - # __pycache__ directory and __pycache__ is by some non-dir node. - return False - elif err == errno.EACCES: - # The directory is read-only; this can happen for example when - # running the tests in a package installed as root - return False - raise + state.trace("error writing pyc file at %s: errno=%s" %(pyc, err)) + # we ignore any failure to write the cache file + # there are many reasons, permission-denied, __pycache__ being a + # file etc. + return False try: fp.write(imp.get_magic()) fp.write(struct.pack("