Do not attempt to rewrite non-source files (#5490)

Do not attempt to rewrite non-source files
This commit is contained in:
Bruno Oliveira 2019-06-25 20:43:23 -03:00 committed by GitHub
commit aaf40314d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 0 deletions

View File

@ -70,6 +70,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)
):