From 2ee4b6926662e15113d99b86f78d29d2b1d1225c Mon Sep 17 00:00:00 2001 From: Marcel Bargull Date: Mon, 6 Nov 2023 16:32:39 +0100 Subject: [PATCH] tests: Filter urllib3 retry warning log messages Some tests like those in tests.cli.test_subcommands assert that there is no output on stderr. If urllib3 retries a connection, it logs a warning message which lets those tests fail. Signed-off-by: Marcel Bargull --- tests/conftest.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index 9cbe6228fcb..031b5274a55 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,5 +1,6 @@ # Copyright (C) 2012 Anaconda, Inc # SPDX-License-Identifier: BSD-3-Clause +from logging import getLogger from pathlib import Path import pytest @@ -66,3 +67,15 @@ def clear_cuda_version(): def do_not_register_envs(monkeypatch): """Do not register environments created during tests""" monkeypatch.setenv("CONDA_REGISTER_ENVS", "false") + + +@pytest.fixture(autouse=True) +def filter_retry_log_warning(): + """Do not register environments created during tests""" + def log_filter(record): + return not re.match("^Retrying .* after connection broken by", record.msg) + + logger = getLogger("urllib3.connectionpool") + logger.addFilter(log_filter) + yield + logger.removeFilter(log_filter)