Don't insert warnings when not in a module

This commit is contained in:
Tomer Keren 2018-12-05 19:49:54 +02:00
parent 7a7ad0c120
commit 8fd60483ef
1 changed files with 6 additions and 5 deletions

View File

@ -841,12 +841,13 @@ class AssertionRewriter(ast.NodeVisitor):
self.push_format_context()
# Rewrite assert into a bunch of statements.
top_condition, explanation = self.visit(assert_.test)
# Check if directly asserting None, in order to warn [Issue #3191]
self.statements.append(
self.warn_about_none_ast(
top_condition, module_path=self.module_path, lineno=assert_.lineno
# If in a test module, check if directly asserting None, in order to warn [Issue #3191]
if self.module_path is not None:
self.statements.append(
self.warn_about_none_ast(
top_condition, module_path=self.module_path, lineno=assert_.lineno
)
)
)
# Create failure message.
body = self.on_failure
negation = ast.UnaryOp(ast.Not(), top_condition)