Don't insert warnings when not in a module
This commit is contained in:
parent
7a7ad0c120
commit
8fd60483ef
|
@ -841,12 +841,13 @@ class AssertionRewriter(ast.NodeVisitor):
|
||||||
self.push_format_context()
|
self.push_format_context()
|
||||||
# Rewrite assert into a bunch of statements.
|
# Rewrite assert into a bunch of statements.
|
||||||
top_condition, explanation = self.visit(assert_.test)
|
top_condition, explanation = self.visit(assert_.test)
|
||||||
# Check if directly asserting None, in order to warn [Issue #3191]
|
# If in a test module, check if directly asserting None, in order to warn [Issue #3191]
|
||||||
self.statements.append(
|
if self.module_path is not None:
|
||||||
self.warn_about_none_ast(
|
self.statements.append(
|
||||||
top_condition, module_path=self.module_path, lineno=assert_.lineno
|
self.warn_about_none_ast(
|
||||||
|
top_condition, module_path=self.module_path, lineno=assert_.lineno
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
# Create failure message.
|
# Create failure message.
|
||||||
body = self.on_failure
|
body = self.on_failure
|
||||||
negation = ast.UnaryOp(ast.Not(), top_condition)
|
negation = ast.UnaryOp(ast.Not(), top_condition)
|
||||||
|
|
Loading…
Reference in New Issue