From b991810f32bc56ec8ab773eac81fccf69647ffb0 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Tue, 25 Jun 2019 08:00:20 -0700 Subject: [PATCH] Do not attempt to rewrite non-source files --- src/_pytest/assertion/rewrite.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/_pytest/assertion/rewrite.py b/src/_pytest/assertion/rewrite.py index cce980005..de33b6058 100644 --- a/src/_pytest/assertion/rewrite.py +++ b/src/_pytest/assertion/rewrite.py @@ -69,6 +69,8 @@ class AssertionRewritingHook: # python3.5 - python3.6: `namespace` # python3.7+: `None` or spec.origin in {None, "namespace"} + # we can only rewrite source files + or not isinstance(spec.loader, importlib.machinery.SourceFileLoader) # if the file doesn't exist, we can't rewrite it or not os.path.exists(spec.origin) ):