summaryrefslogtreecommitdiff
path: root/_pytest/assertion
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2016-11-20 11:56:15 -0500
committerNed Batchelder <ned@nedbatchelder.com>2016-11-20 13:09:32 -0500
commit06bb61bbe31829955b36451829fdb9b4ffedc65b (patch)
tree73cfdf0b3eaf33631cf901b78e130e48d35b6a0b /_pytest/assertion
parentcbf261c74ef1713f88ac56f2c382f096b252dedb (diff)
downloadpytest-06bb61bbe31829955b36451829fdb9b4ffedc65b.tar.gz
Don't fail if imp can't find the source for a .pyc file. #2038
Diffstat (limited to '_pytest/assertion')
-rw-r--r--_pytest/assertion/rewrite.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/_pytest/assertion/rewrite.py b/_pytest/assertion/rewrite.py
index 6b4c1f483..9136c3867 100644
--- a/_pytest/assertion/rewrite.py
+++ b/_pytest/assertion/rewrite.py
@@ -80,7 +80,12 @@ class AssertionRewritingHook(object):
tp = desc[2]
if tp == imp.PY_COMPILED:
if hasattr(imp, "source_from_cache"):
- fn = imp.source_from_cache(fn)
+ try:
+ fn = imp.source_from_cache(fn)
+ except ValueError:
+ # Python 3 doesn't like orphaned but still-importable
+ # .pyc files.
+ fn = fn[:-1]
else:
fn = fn[:-1]
elif tp != imp.PY_SOURCE: