Skip to content

Commit 2e42d93

Browse files
committed
Display the filename when encountering SyntaxWarning.
```console $ cd t && rm -rf __pycache__ && pytest t.py -q -c /dev/null; cd .. . [100%] =============================== warnings summary =============================== <unknown>:2: DeprecationWarning: invalid escape sequence \. -- Docs: https://docs.pytest.org/en/latest/warnings.html 1 passed, 1 warnings in 0.01 seconds ``` ```console $ cd t && rm -rf __pycache__ && pytest t.py -q -c /dev/null; cd .. . [100%] =============================== warnings summary =============================== /tmp/pytest/t/t.py:2: DeprecationWarning: invalid escape sequence \. '\.wat' -- Docs: https://docs.pytest.org/en/latest/warnings.html 1 passed, 1 warnings in 0.01 seconds ```
1 parent 6258248 commit 2e42d93

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

changelog/4152.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Display the filename when encountering ``SyntaxWarning``.

src/_pytest/assertion/rewrite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ def _rewrite_test(config, fn):
398398
finally:
399399
del state._indecode
400400
try:
401-
tree = ast.parse(source)
401+
tree = ast.parse(source, filename=fn.strpath)
402402
except SyntaxError:
403403
# Let this pop up again in the real import.
404404
state.trace("failed to parse: %r" % (fn,))

0 commit comments

Comments
 (0)