Skip to content

Commit faaf778

Browse files
committed
Add test for PermissionError. Ref #181.
1 parent d2529ff commit faaf778

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

conftest.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import sys
33
import platform
4+
import pathlib
45

56
import pytest
67
import path
@@ -150,8 +151,18 @@ def suppress_path_mangle(monkeysession):
150151
)
151152

152153

154+
def _set_home(monkeypatch, path):
155+
var = 'USERPROFILE' if platform.system() == 'Windows' else 'HOME'
156+
monkeypatch.setenv(var, str(path))
157+
return path
158+
159+
153160
@pytest.fixture
154161
def temp_home(tmp_path, monkeypatch):
155-
var = 'USERPROFILE' if platform.system() == 'Windows' else 'HOME'
156-
monkeypatch.setenv(var, str(tmp_path))
157-
return tmp_path
162+
return _set_home(monkeypatch, tmp_path)
163+
164+
165+
@pytest.fixture
166+
def fake_home(fs, monkeypatch):
167+
home = fs.create_dir('/fakehome')
168+
return _set_home(monkeypatch, pathlib.Path(home.path))

distutils/tests/test_dist.py

+13
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,19 @@ def test_find_config_files_disable(self, temp_home):
258258
# make sure --no-user-cfg disables the user cfg file
259259
assert len(all_files) - 1 == len(files)
260260

261+
@pytest.mark.xfail(reason="pypa/distutils#181", strict=True)
262+
@pytest.mark.skipif(
263+
'platform.system() == "Windows"',
264+
reason='Windows does not honor chmod 000',
265+
)
266+
def test_find_config_files_permission_error(self, fake_home):
267+
"""
268+
Finding config files should not fail when directory is inaccessible.
269+
"""
270+
fake_home.joinpath(pydistutils_cfg).write_text('')
271+
fake_home.chmod(0o000)
272+
Distribution().find_config_files()
273+
261274

262275
@pytest.mark.usefixtures('save_env')
263276
@pytest.mark.usefixtures('save_argv')

tox.ini

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ deps =
2020
jaraco.text
2121
path
2222
docutils
23+
pyfakefs
2324
commands =
2425
pytest {posargs}
2526
setenv =

0 commit comments

Comments
 (0)