Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #3671 - filterwarnings Is an Unregistered Marker #3815

Merged
merged 6 commits into from Aug 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Expand Up @@ -182,6 +182,7 @@ Russel Winder
Ryan Wooden
Samuel Dion-Girardeau
Samuele Pedroni
Sankt Petersbug
Segev Finer
Serhii Mozghovyi
Simon Gomizelj
Expand Down
1 change: 1 addition & 0 deletions changelog/3671.bugfix.rst
@@ -0,0 +1 @@
Fix ``filterwarnings`` mark not registered
8 changes: 8 additions & 0 deletions src/_pytest/warnings.py
Expand Up @@ -49,6 +49,14 @@ def pytest_addoption(parser):
)


def pytest_configure(config):
config.addinivalue_line(
"markers",
"filterwarnings(warning): add a warning filter to the given test. "
"see http://pytest.org/latest/warnings.html#pytest-mark-filterwarnings ",
)


@contextmanager
def catch_warnings_for_item(item):
"""
Expand Down
15 changes: 15 additions & 0 deletions testing/test_warnings.py
Expand Up @@ -287,3 +287,18 @@ def test():
)
result = testdir.runpytest("-W", "always")
result.stdout.fnmatch_lines(["*= 1 passed, 1 warnings in *"])


def test_filterwarnings_mark_registration(testdir):
"""Ensure filterwarnings mark is registered"""
testdir.makepyfile(
"""
import pytest

@pytest.mark.filterwarnings('error')
def test_func():
pass
"""
)
result = testdir.runpytest("--strict")
assert result.ret == 0