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.
This commit is contained in:
Jean Abou-Samra 2023-01-31 23:10:48 +01:00 committed by GitHub
parent 4c4745af9c
commit ecfd08d325
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,9 +5,23 @@ import docutils
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