diff --git a/changelog/3191.feature.rst b/changelog/3191.feature.rst index 13d2049bf..4b1626eed 100644 --- a/changelog/3191.feature.rst +++ b/changelog/3191.feature.rst @@ -10,7 +10,8 @@ When they should write:: Because the ``assert_called_with`` method of mock objects already executes an assertion. -This warning will not be issued when ``None`` is explicitly checked - assert none_returning_fun() is None +This warning will not be issued when ``None`` is explicitly checked. An assertion like:: + + assert variable is None will not issue the warning diff --git a/src/_pytest/assertion/rewrite.py b/src/_pytest/assertion/rewrite.py index bfb81cf85..e819b8da2 100644 --- a/src/_pytest/assertion/rewrite.py +++ b/src/_pytest/assertion/rewrite.py @@ -885,8 +885,7 @@ class AssertionRewriter(ast.NodeVisitor): warnings.warn_explicit( PytestWarning('assertion the value None, Please use "assert is None"'), category=None, - # filename=str(self.module_path), - filename=__file__ + filename=str, lineno=node.lineno, ) """ @@ -905,7 +904,7 @@ warn_explicit( lineno={lineno}, ) """.format( - filename=str(module_path), lineno=lineno + filename=module_path.strpath, lineno=lineno ) ).body return ast.If(val_is_none, send_warning, [])