Skip to content

SyntaxWarnings are difficult to trace with pytest #4152

@asottile

Description

@asottile

source

def test():
    '\.wat'

cmdline

first: run and it gives a warning as expected, but the source is <unknown> 😭

$ pytest t.py 
============================= test session starts ==============================
platform linux -- Python 3.6.6, pytest-3.8.2, py-1.7.0, pluggy-0.7.1
rootdir: /tmp/t, inifile:
collected 1 item                                                               

t.py .                                                                   [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 =====================

next: run again, and the warning is not to be seen (this is probably fine, it's gobbled now that the file is loaded by pyc -- we'd have to take a performance hit every time for this -- mostly pointing this out in case anyone else finds this:

$ pytest t.py 
============================= test session starts ==============================
platform linux -- Python 3.6.6, pytest-3.8.2, py-1.7.0, pluggy-0.7.1
rootdir: /tmp/t, inifile:
collected 1 item                                                               

t.py .                                                                   [100%]

=========================== 1 passed in 0.01 seconds ===========================

next: can restore it by rm -rf __pycache__ before:

$ rm -rf __pycache__/ && pytest t.py 
============================= test session starts ==============================
platform linux -- Python 3.6.6, pytest-3.8.2, py-1.7.0, pluggy-0.7.1
rootdir: /tmp/t, inifile:
collected 1 item                                                               

t.py .                                                                   [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 =====================

/me rolls up sleeves -- let me see if I can make the warning summary better, I have some ideas

Metadata

Metadata

Assignees

No one assigned

    Labels

    plugin: warningsrelated to the warnings builtin plugintype: enhancementnew feature or API change, should be merged into features branch

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions