From ecfd08d3254587972299c23cd596660f5796099c Mon Sep 17 00:00:00 2001 From: Jean Abou-Samra Date: Tue, 31 Jan 2023 23:10:48 +0100 Subject: [PATCH] Skip sphinx.locale.init_console when running tests (#11159) Tests for Sphinx's CLIs, like test_apidoc, indirectly init_console to initialize translations for Sphinx's console domain, the one with Sphinx's log messages. This bleeds over subsequent tests by making warnings translated. Fix this by skipping init_console when running Sphinx's test suite. --- tests/conftest.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index ebbc9e2c7f6..3934203eab3 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -5,9 +5,23 @@ import pytest import sphinx +import sphinx.locale from sphinx.testing import comparer from sphinx.testing.path import path + +def _init_console(locale_dir=sphinx.locale._LOCALE_DIR, catalog='sphinx'): + """Monkeypatch ``init_console`` to skip its action. + + Some tests rely on warning messages in English. We don't want + CLI tests to bleed over those tests and make their warnings + translated. + """ + return sphinx.locale.NullTranslations(), False + + +sphinx.locale.init_console = _init_console + pytest_plugins = 'sphinx.testing.fixtures' # Exclude 'roots' dirs for pytest test collector