From 6c1d114d1420ead023932c1a9ff07e7df9a2a431 Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Mon, 8 Nov 2021 23:24:58 +0100 Subject: [PATCH] Simplify 'test_can_read_toml_env_variable' to work like other tests See initial intent in https://github.com/PyCQA/pylint/issues/3839 This permit to not use the OptionManagerMixin directly, which is problematic when it needs the function defined in Pylinter or other classes. --- tests/config/test_config.py | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/tests/config/test_config.py b/tests/config/test_config.py index daf04bbfa06..d4e7fdd24f3 100644 --- a/tests/config/test_config.py +++ b/tests/config/test_config.py @@ -1,16 +1,14 @@ # pylint: disable=missing-module-docstring, missing-function-docstring, protected-access import os import unittest.mock -from pathlib import PosixPath - -import pytest +from pathlib import Path, PosixPath +from typing import Union import pylint.lint -from pylint.config import OptionsManagerMixIn from pylint.lint.run import Run -def check_configuration_file_reader(config_file: PosixPath) -> Run: +def check_configuration_file_reader(config_file: Union[str, Path]) -> Run: """Initialize pylint with the given configuration file and check that what we initialized the linter with what was expected. """ @@ -101,6 +99,7 @@ def test_can_read_toml_rich_types(tmp_path: PosixPath) -> None: def test_can_read_toml_env_variable(tmp_path: PosixPath) -> None: """We can read and open a properly formatted toml file.""" + os.environ["tmp_path_env"] = str(tmp_path / "pyproject.toml") config_file = tmp_path / "pyproject.toml" config_file.write_text( """ @@ -110,17 +109,4 @@ def test_can_read_toml_env_variable(tmp_path: PosixPath) -> None: reports = "yes" """ ) - os.environ["tmp_path_env"] = str(tmp_path / "pyproject.toml") - options_manager_mix_in = OptionsManagerMixIn("", "${tmp_path_env}") - options_manager_mix_in.read_config_file("${tmp_path_env}") - - def test_read_config_file() -> None: - with pytest.raises(OSError): - options_manager_mix_in.read_config_file("${tmp_path_en}") - - test_read_config_file() - options_manager_mix_in.load_config_file() - section = options_manager_mix_in.cfgfile_parser.sections()[0] - jobs, jobs_nr = options_manager_mix_in.cfgfile_parser.items(section)[1] - assert jobs == "jobs" - assert jobs_nr == "10" + check_configuration_file_reader("${tmp_path_env}")