Skip to content

SyntaxWarnings re-triggered during expected failure #4260

@asottile

Description

@asottile
import pytest


def test():
    '\d'  # should be a warning


@pytest.mark.xfail
def test_expected_failure():
    assert False
$ pytest t.py
============================= test session starts ==============================
platform linux -- Python 3.6.6, pytest-3.9.3, py-1.7.0, pluggy-0.8.0
rootdir: /tmp/t, inifile:
collected 2 items                                                              

t.py .x                                                                  [100%]

=============================== warnings summary ===============================
t.py:5
  /tmp/t/t.py:5: DeprecationWarning: invalid escape sequence \d
    '\d'  # should be a warning

t.py::test_expected_failure
  source:5: DeprecationWarning: invalid escape sequence \d

-- Docs: https://docs.pytest.org/en/latest/warnings.html
=============== 1 passed, 1 xfailed, 2 warnings in 0.04 seconds ================

I was at first confused by the "source" bit, that appears to come from here:

astnode = compile(content, "source", "exec", 1024) # 1024 for AST

would have to change the signature probably to pass along the filename so that doesn't say "source" in the output. Might have to do some other clever things to make sure it doesn't get invoked at all when unnecessary 🤷‍♂️

Metadata

Metadata

Assignees

No one assigned

    Labels

    plugin: warningsrelated to the warnings builtin plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions