From 3252697c11a66c47b783dc3e0c2066f4cd8799df Mon Sep 17 00:00:00 2001 From: Brock Date: Fri, 30 Oct 2020 12:59:48 -0700 Subject: [PATCH] TST: suppress warnings we cant do anything about --- pandas/tests/io/excel/test_readers.py | 2 -- pandas/tests/io/pytables/__init__.py | 9 +++++++++ pandas/util/_test_decorators.py | 19 +++++++++++++++---- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/pandas/tests/io/excel/test_readers.py b/pandas/tests/io/excel/test_readers.py index c474e67123ef7..e9eaa95ca2ca3 100644 --- a/pandas/tests/io/excel/test_readers.py +++ b/pandas/tests/io/excel/test_readers.py @@ -21,7 +21,6 @@ "xlrd", marks=[ td.skip_if_no("xlrd"), - pytest.mark.filterwarnings("ignore:.*(tree\\.iter|html argument)"), ], ), pytest.param( @@ -35,7 +34,6 @@ None, marks=[ td.skip_if_no("xlrd"), - pytest.mark.filterwarnings("ignore:.*(tree\\.iter|html argument)"), ], ), pytest.param("pyxlsb", marks=td.skip_if_no("pyxlsb")), diff --git a/pandas/tests/io/pytables/__init__.py b/pandas/tests/io/pytables/__init__.py index e69de29bb2d1d..fb4b317a5e977 100644 --- a/pandas/tests/io/pytables/__init__.py +++ b/pandas/tests/io/pytables/__init__.py @@ -0,0 +1,9 @@ +import pytest + +pytestmark = [ + # pytables https://github.com/PyTables/PyTables/issues/822 + pytest.mark.filterwarnings( + "ignore:a closed node found in the registry:UserWarning" + ), + pytest.mark.filterwarnings(r"ignore:tostring\(\) is deprecated:DeprecationWarning"), +] diff --git a/pandas/util/_test_decorators.py b/pandas/util/_test_decorators.py index e3b779678c68b..209a4233fc3b7 100644 --- a/pandas/util/_test_decorators.py +++ b/pandas/util/_test_decorators.py @@ -27,6 +27,7 @@ def test_foo(): from distutils.version import LooseVersion import locale from typing import Callable, Optional +import warnings import numpy as np import pytest @@ -51,10 +52,20 @@ def safe_import(mod_name: str, min_version: Optional[str] = None): object The imported module if successful, or False """ - try: - mod = __import__(mod_name) - except ImportError: - return False + with warnings.catch_warnings(): + # Suppress warnings that we can't do anything about, + # e.g. from aiohttp + warnings.filterwarnings( + "ignore", + category=DeprecationWarning, + module="aiohttp", + message=".*decorator is deprecated since Python 3.8.*", + ) + + try: + mod = __import__(mod_name) + except ImportError: + return False if not min_version: return mod