diff --git a/tests/helper.py b/tests/helper.py index d294eaef8..315264e34 100644 --- a/tests/helper.py +++ b/tests/helper.py @@ -4,6 +4,7 @@ import functools import importlib.machinery import importlib.util +import locale import os import pathlib import shutil @@ -103,6 +104,14 @@ def read_shebang(command: str) -> str | None: return first_line.decode().split(" ", 1)[0][2:] +@contextlib.contextmanager +def restore_locale(category: int) -> Generator[None]: + """Restore locale after leaving this context manager.""" + orig_locale = locale.getlocale(category) + yield + locale.setlocale(category, orig_locale) + + @contextlib.contextmanager def restore_os_environ() -> Generator[None]: """Restore os.environ after leaving this context manager.""" diff --git a/tests/system/test_packaging_apt_dpkg.py b/tests/system/test_packaging_apt_dpkg.py index fee721ffa..45ba0565a 100644 --- a/tests/system/test_packaging_apt_dpkg.py +++ b/tests/system/test_packaging_apt_dpkg.py @@ -4,6 +4,7 @@ import glob import gzip +import locale import os import pathlib import shutil @@ -17,7 +18,7 @@ import pytest from apport.packaging_impl.apt_dpkg import _parse_deb822_sources, impl -from tests.helper import has_internet +from tests.helper import has_internet, restore_locale from tests.paths import get_test_data_directory if shutil.which("dpkg") is None: @@ -348,10 +349,12 @@ def test_install_packages_system( @pytest.mark.skipif(not has_internet(), reason="online test") +@restore_locale(locale.LC_MESSAGES) def test_install_packages_error( configdir: str, cachedir: str, rootdir: str, apt_style: AptStyle ) -> None: """install_packages() with errors""" + locale.setlocale(locale.LC_MESSAGES, "C.UTF-8") # sources.list with invalid format release = _setup_foonux_config(configdir, apt_style) with open(