diff --git a/conftest.py b/conftest.py index ef3e100c..76903f56 100644 --- a/conftest.py +++ b/conftest.py @@ -1,6 +1,7 @@ import os import sys import platform +import pathlib import pytest import path @@ -150,8 +151,18 @@ def suppress_path_mangle(monkeysession): ) +def _set_home(monkeypatch, path): + var = 'USERPROFILE' if platform.system() == 'Windows' else 'HOME' + monkeypatch.setenv(var, str(path)) + return path + + @pytest.fixture def temp_home(tmp_path, monkeypatch): - var = 'USERPROFILE' if platform.system() == 'Windows' else 'HOME' - monkeypatch.setenv(var, str(tmp_path)) - return tmp_path + return _set_home(monkeypatch, tmp_path) + + +@pytest.fixture +def fake_home(fs, monkeypatch): + home = fs.create_dir('/fakehome') + return _set_home(monkeypatch, pathlib.Path(home.path)) diff --git a/distutils/tests/test_dist.py b/distutils/tests/test_dist.py index 25628156..0f205fe4 100644 --- a/distutils/tests/test_dist.py +++ b/distutils/tests/test_dist.py @@ -258,6 +258,19 @@ def test_find_config_files_disable(self, temp_home): # make sure --no-user-cfg disables the user cfg file assert len(all_files) - 1 == len(files) + @pytest.mark.xfail(reason="pypa/distutils#181", strict=True) + @pytest.mark.skipif( + 'platform.system() == "Windows"', + 'Windows does not honor chmod 000', + ) + def test_find_config_files_permission_error(self, fake_home): + """ + Finding config files should not fail when directory is inaccessible. + """ + fake_home.joinpath(pydistutils_cfg).write_text('') + fake_home.chmod(0o000) + Distribution().find_config_files() + @pytest.mark.usefixtures('save_env') @pytest.mark.usefixtures('save_argv') diff --git a/tox.ini b/tox.ini index 3d031d20..c23177c1 100644 --- a/tox.ini +++ b/tox.ini @@ -20,6 +20,7 @@ deps = jaraco.text path docutils + pyfakefs commands = pytest {posargs} setenv =