From fd4485a5407564cc2900e47405d0d665db499988 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Sat, 2 Aug 2014 18:01:28 -0300 Subject: [PATCH] Fixed assertionrewrite._read_pyc to handle corrupted pyc files properly This seems to be the cause for issues #437 and #301. --HG-- branch : assertionrewrite-currupted-pyc --- _pytest/assertion/rewrite.py | 5 ++++- testing/test_assertrewrite.py | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/_pytest/assertion/rewrite.py b/_pytest/assertion/rewrite.py index 95bf4117d..589dc07d2 100644 --- a/_pytest/assertion/rewrite.py +++ b/_pytest/assertion/rewrite.py @@ -308,7 +308,10 @@ def _read_pyc(source, pyc): if (len(data) != 8 or data[:4] != imp.get_magic() or struct.unpack(" strip_bytes + pyc.write(contents[:strip_bytes], mode='wb') + + assert _read_pyc(source, str(pyc)) is None # no error