diff options
author | Mikhail f. Shiryaev <mr.felixoid@gmail.com> | 2023-04-30 22:48:34 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-30 22:48:34 +0200 |
commit | f8288842e58a8b6007ff15ab380c84b00eb9b7a3 (patch) | |
tree | 727cd5397b5fa88d9fa3f0d7f55af36280911bc9 /tests | |
parent | c2ac6f1e905b263adb32102c87150a0c607e4db0 (diff) | |
download | pylint-git-f8288842e58a8b6007ff15ab380c84b00eb9b7a3.tar.gz |
Search for pyproject.toml config file in parent dirs (#7163)
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
Co-authored-by: Daniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/config/test_find_default_config_files.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/config/test_find_default_config_files.py b/tests/config/test_find_default_config_files.py index f78f640b2..0b513a3d5 100644 --- a/tests/config/test_find_default_config_files.py +++ b/tests/config/test_find_default_config_files.py @@ -130,6 +130,47 @@ def test_pylintrc_parentdir() -> None: @pytest.mark.usefixtures("pop_pylintrc") +def test_pyproject_toml_parentdir() -> None: + """Test the search of pyproject.toml file in parent directories""" + with tempdir() as chroot: + with fake_home(): + chroot_path = Path(chroot) + files = [ + "pyproject.toml", + "git/pyproject.toml", + "git/a/pyproject.toml", + "git/a/.git", + "git/a/b/c/__init__.py", + "hg/pyproject.toml", + "hg/a/pyproject.toml", + "hg/a/.hg", + "hg/a/b/c/__init__.py", + "none/sub/__init__.py", + ] + testutils.create_files(files) + for config_file in files: + if config_file.endswith("pyproject.toml"): + with open(config_file, "w", encoding="utf-8") as fd: + fd.write('[tool.pylint."messages control"]\n') + results = { + "": chroot_path / "pyproject.toml", + "git": chroot_path / "git" / "pyproject.toml", + "git/a": chroot_path / "git" / "a" / "pyproject.toml", + "git/a/b": chroot_path / "git" / "a" / "pyproject.toml", + "git/a/b/c": chroot_path / "git" / "a" / "pyproject.toml", + "hg": chroot_path / "hg" / "pyproject.toml", + "hg/a": chroot_path / "hg" / "a" / "pyproject.toml", + "hg/a/b": chroot_path / "hg" / "a" / "pyproject.toml", + "hg/a/b/c": chroot_path / "hg" / "a" / "pyproject.toml", + "none": chroot_path / "pyproject.toml", + "none/sub": chroot_path / "pyproject.toml", + } + for basedir, expected in results.items(): + os.chdir(chroot_path / basedir) + assert next(config.find_default_config_files(), None) == expected + + +@pytest.mark.usefixtures("pop_pylintrc") def test_pylintrc_parentdir_no_package() -> None: """Test that we don't find a pylintrc in sub-packages.""" with tempdir() as chroot: |