Skip to content

Commit

Permalink
Merge pull request #3509 from nicoddemus/marshal-3503
Browse files Browse the repository at this point in the history
Write rewritten code using file.write(marshal.dumps())
  • Loading branch information
nicoddemus authored May 26, 2018
2 parents a36bab4 + b5a94d8 commit 1d451c7
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
5 changes: 1 addition & 4 deletions _pytest/assertion/rewrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,7 @@ def _write_pyc(state, co, source_stat, pyc):
mtime = int(source_stat.mtime)
size = source_stat.size & 0xFFFFFFFF
fp.write(struct.pack("<ll", mtime, size))
if six.PY2:
marshal.dump(co, fp.file)
else:
marshal.dump(co, fp)
fp.write(marshal.dumps(co))
except EnvironmentError as e:
state.trace("error writing pyc file at %s: errno=%s" % (pyc, e.errno))
# we ignore any failure to write the cache file
Expand Down
1 change: 1 addition & 0 deletions changelog/3503.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix assertion rewriter compatibility with libraries that monkey patch ``file`` objects.

0 comments on commit 1d451c7

Please sign in to comment.