-
Notifications
You must be signed in to change notification settings - Fork 2
/
conftest.py
38 lines (28 loc) · 1.03 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""A pytest ``conftest.py`` file."""
import re
import logging
import warnings
import pytest
import rdkit
from packaging.version import Version
from CAT import logger
@pytest.fixture(scope="session", autouse=True)
def rdkit_version() -> None:
"""Validate the rdkit version."""
if Version(rdkit.__version__) < Version("2021.03.4"):
warnings.warn(
"The CAT test suite requires RDKit >= 2021.03.4 to properly run; "
f"observed version: {rdkit.__version__}"
)
class TestFilter(logging.Filter):
def filter(self, record: logging.LogRecord) -> bool:
if re.fullmatch(r"The optional [\-a-zA-Z]+ package was not found", record.msg):
return False
return True
@pytest.fixture(scope="session", autouse=True)
def modify_logger() -> None:
"""Suppres the loggers ``stderr`` output and filter out all optional-package warnings."""
for handler in logger.handlers.copy():
logger.removeHandler(handler)
filter = TestFilter(logger.name)
logger.addFilter(filter)