Skip to content

filterwarnings mark escapes regular expressions #3936

Closed
@nicoddemus

Description

@nicoddemus

The following example should not print any warnings:

import pytest, warnings

@pytest.mark.filterwarnings(r"ignore:some \(warning\)")
def test_foo():
    warnings.warn(UserWarning("some (warning)"))     
λ pytest .tmp\test-warn-regex.py
======================== test session starts ========================
...
collected 1 item

.tmp\test-warn-regex.py .                                      [100%]

========================= warnings summary ==========================
test-warn-regex.py::test_foo
  c:\pytest\.tmp\test-warn-regex.py:6: UserWarning: some (warning)
    warnings.warn(UserWarning("some (warning)"))

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    plugin: warningsrelated to the warnings builtin plugintype: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions