Skip to content

Commit

Permalink
catch logging.* usage during tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TicClick committed Apr 16, 2021
1 parent f58b6ee commit c37bf4f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 0 additions & 1 deletion librarian/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@


def configure_client(config):
# TODO: ban logging.{debug,info,warning,error,critical} which I sometimes call by mistake
loggers = logging_utils.all_loggers()
loggers["librarian.main"] = logger # otherwise an old copy with default settings is kept
logging_utils.setup_logging(config["runtime"]["dir"], config["logging"], loggers.values())
Expand Down
14 changes: 14 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,17 @@ def inner():
@pytest.fixture
def assignee_login():
return "assignee-login"


@pytest.fixture(autouse=True)
def patch_logging(mocker):
class WrongLoggingAPIUsedException(Exception):
pass

for method in ("debug", "info", "warning", "error", "critical", "log"):
mocker.patch(
f"logging.{method}",
side_effect=WrongLoggingAPIUsedException(
"Attempt to use logging.* methods detected -- check the stacktrace"
)
)

0 comments on commit c37bf4f

Please sign in to comment.