diff --git a/changelog/4152.bugfix.rst b/changelog/4152.bugfix.rst new file mode 100644 index 000000000..ce2547294 --- /dev/null +++ b/changelog/4152.bugfix.rst @@ -0,0 +1 @@ +Display the filename when encountering ``SyntaxWarning``. diff --git a/src/_pytest/assertion/rewrite.py b/src/_pytest/assertion/rewrite.py index 7a11c4ec1..385ae4e77 100644 --- a/src/_pytest/assertion/rewrite.py +++ b/src/_pytest/assertion/rewrite.py @@ -398,7 +398,7 @@ def _rewrite_test(config, fn): finally: del state._indecode try: - tree = ast.parse(source) + tree = ast.parse(source, filename=fn.strpath) except SyntaxError: # Let this pop up again in the real import. state.trace("failed to parse: %r" % (fn,))