Skip to content

Commit

Permalink
MAINT: Do not modify global logging settings when configuring the CAT…
Browse files Browse the repository at this point in the history
… logger (#207)
  • Loading branch information
BvB93 authored Nov 29, 2021
1 parent a041442 commit 988a910
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 17 deletions.
5 changes: 0 additions & 5 deletions CAT/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@

# flake8: noqa: E402

import logging
_mpl_logger = logging.getLogger('matplotlib')
_mpl_logger.setLevel(logging.INFO)
del _mpl_logger, logging

from .__version__ import __version__ as __version__
__author__ = "Bas van Beek"
__email__ = '[email protected]'
Expand Down
13 changes: 9 additions & 4 deletions CAT/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@

__all__ = ['logger']

#: A logger for CAT
#: The CAT logger
logger = logging.getLogger('CAT')
logging.basicConfig(level=logging.DEBUG,
format='[%(asctime)s] %(levelname)s: %(message)s',
datefmt='%H:%M:%S')
_handler = logging.StreamHandler()
_handler.setLevel(logging.DEBUG)
_handler.setFormatter(logging.Formatter(
fmt='[%(asctime)s] %(levelname)s: %(message)s',
datefmt='%H:%M:%S',
))
logger.addHandler(_handler)
del _handler


def log_start(job: Job, mol: Molecule, job_preset: str, job_name: str) -> None:
Expand Down
8 changes: 0 additions & 8 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
"""A pytest ``conftest.py`` file."""

import logging
from typing import Any

import pytest
import rdkit

from nanoutils import VersionInfo


def pytest_configure(config: Any) -> None:
logging.getLogger("filelock").setLevel(logging.WARNING)
logging.getLogger("CAT").setLevel(logging.WARNING)


@pytest.fixture(scope="session", autouse=True)
def rdkit_version() -> None:
rdkit_version = VersionInfo.from_str(rdkit.__version__)
Expand Down
17 changes: 17 additions & 0 deletions tests/test_logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import sys
import subprocess

CODE = r"""\
import logging
from assertionlib import assertion
assertion.len_eq(logging.root.handlers, 0)
import CAT
assertion.len_eq(logging.root.handlers, 0)
"""


def test_basic_config() -> None:
p = subprocess.run([sys.executable, '-c', CODE], encoding="utf8", stderr=subprocess.PIPE)
if p.returncode:
raise AssertionError(f"Non-zero return code: {p.returncode!r}\n\n{p.stderr}")

0 comments on commit 988a910

Please sign in to comment.