Skip to content

Commit 1d451c7

Browse files
authored
Merge pull request #3509 from nicoddemus/marshal-3503
Write rewritten code using file.write(marshal.dumps())
2 parents a36bab4 + b5a94d8 commit 1d451c7

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

_pytest/assertion/rewrite.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,7 @@ def _write_pyc(state, co, source_stat, pyc):
267267
mtime = int(source_stat.mtime)
268268
size = source_stat.size & 0xFFFFFFFF
269269
fp.write(struct.pack("<ll", mtime, size))
270-
if six.PY2:
271-
marshal.dump(co, fp.file)
272-
else:
273-
marshal.dump(co, fp)
270+
fp.write(marshal.dumps(co))
274271
except EnvironmentError as e:
275272
state.trace("error writing pyc file at %s: errno=%s" % (pyc, e.errno))
276273
# we ignore any failure to write the cache file

changelog/3503.bugfix.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix assertion rewriter compatibility with libraries that monkey patch ``file`` objects.

0 commit comments

Comments
 (0)