Skip to content

Commit

Permalink
Dynamically add filtered warnings in pytest
Browse files Browse the repository at this point in the history
Ref #355
  • Loading branch information
webknjaz committed Jan 5, 2021
1 parent b63173d commit 3eebb80
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
29 changes: 19 additions & 10 deletions cheroot/test/_pytest_plugin.py
Expand Up @@ -11,19 +11,28 @@


pytest_version = tuple(map(int, __version__.split('.')))
unraisable_exceptions = {
('pytest', 'PytestUnhandledThreadExceptionWarning'),
('pytest', 'PytestUnraisableExceptionWarning'),
}


def pytest_load_initial_conftests(early_config, parser, args):
"""Drop unfilterable warning ignores."""
if pytest_version >= (6, 2, 0):
if pytest_version < (6, 2, 0):
return

early_config._inicache['filterwarnings'] = [
fw for fw in early_config.getini('filterwarnings')
if fw.count(':') < 2 or
tuple(fw.split(':')[2].split('.')[:2]) not in unraisable_exceptions
]
# pytest>=6.2.0 under Python 3.8:
# Refs:
# * https://docs.pytest.org/en/stable/usage.html#unraisable
# * https://github.com/pytest-dev/pytest/issues/5299
early_config._inicache['filterwarnings'].extend((
'ignore:Exception in thread CP Server Thread-:'
'pytest.PytestUnhandledThreadExceptionWarning:_pytest.threadexception',
'ignore:Exception in thread Thread-:'
'pytest.PytestUnhandledThreadExceptionWarning:_pytest.threadexception',
'ignore:Exception ignored in. '
'<socket.socket fd=-1, family=AddressFamily.AF_INET, '
'type=SocketKind.SOCK_STREAM, proto=6>:'
'pytest.PytestUnraisableExceptionWarning:_pytest.unraisableexception',
'ignore:Exception ignored in. '
'<socket.socket fd=-1, family=AddressFamily.AF_INET6, '
'type=SocketKind.SOCK_STREAM, proto=6>:'
'pytest.PytestUnraisableExceptionWarning:_pytest.unraisableexception',
))
8 changes: 0 additions & 8 deletions pytest.ini
Expand Up @@ -33,14 +33,6 @@ doctest_optionflags = ALLOW_UNICODE ELLIPSIS
filterwarnings =
error

# pytest>=6.2.0 under Python 3.8:
# Ref: https://docs.pytest.org/en/stable/usage.html#unraisable
# Ref: https://github.com/pytest-dev/pytest/issues/5299
ignore:Exception in thread CP Server Thread-:pytest.PytestUnhandledThreadExceptionWarning:_pytest.threadexception
ignore:Exception in thread Thread-:pytest.PytestUnhandledThreadExceptionWarning:_pytest.threadexception
ignore:Exception ignored in. <socket.socket fd=-1, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6>:pytest.PytestUnraisableExceptionWarning:_pytest.unraisableexception
ignore:Exception ignored in. <socket.socket fd=-1, family=AddressFamily.AF_INET6, type=SocketKind.SOCK_STREAM, proto=6>:pytest.PytestUnraisableExceptionWarning:_pytest.unraisableexception

# cryptography==3.0 warning:
# `cryptography.utils.CryptographyDeprecationWarning` happens but we
# cannot import it because of the chicken-egg nature of its
Expand Down

0 comments on commit 3eebb80

Please sign in to comment.