Skip to content

Commit 1d53329

Browse files
committed
Merge branch 'bugfix/94-bad-path' into 'master'
Capture expectation that an inaccessible directory in sys.path shouldn't error See merge request python-devs/importlib_metadata!107
2 parents e4f1258 + 78a0381 commit 1d53329

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

importlib_metadata/tests/fixtures.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,19 @@ def tempdir_as_cwd():
4747
yield tmp
4848

4949

50-
class SiteDir:
50+
class Fixtures:
5151
def setUp(self):
5252
self.fixtures = ExitStack()
5353
self.addCleanup(self.fixtures.close)
54+
55+
56+
class SiteDir(Fixtures):
57+
def setUp(self):
58+
super(SiteDir, self).setUp()
5459
self.site_dir = self.fixtures.enter_context(tempdir())
5560

5661

57-
class OnSysPath:
62+
class OnSysPath(Fixtures):
5863
@staticmethod
5964
@contextlib.contextmanager
6065
def add_sys_path(dir):

importlib_metadata/tests/test_main.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import unittest
99
import importlib
1010
import importlib_metadata
11+
import pyfakefs.fake_filesystem_unittest as ffs
1112

1213
from . import fixtures
1314
from .. import (
@@ -193,6 +194,33 @@ def test_egg(self):
193194
version('foo')
194195

195196

197+
class MissingSysPath(fixtures.OnSysPath, unittest.TestCase):
198+
site_dir = '/does-not-exist'
199+
200+
def test_discovery(self):
201+
"""
202+
Discovering distributions should succeed even if
203+
there is an invalid path on sys.path.
204+
"""
205+
importlib_metadata.distributions()
206+
207+
208+
class InaccessibleSysPath(fixtures.OnSysPath, ffs.TestCase):
209+
site_dir = '/access-denied'
210+
211+
def setUp(self):
212+
super(InaccessibleSysPath, self).setUp()
213+
self.setUpPyfakefs()
214+
self.fs.create_dir(self.site_dir, perm_bits=000)
215+
216+
def test_discovery(self):
217+
"""
218+
Discovering distributions should succeed even if
219+
there is an invalid path on sys.path.
220+
"""
221+
list(importlib_metadata.distributions())
222+
223+
196224
class TestEntryPoints(unittest.TestCase):
197225
def __init__(self, *args):
198226
super(TestEntryPoints, self).__init__(*args)

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ passenv =
2828
deps =
2929
cov,diffcov: coverage>=4.5
3030
diffcov: diff_cover
31+
pyfakefs
3132
setenv =
3233
cov: COVERAGE_PROCESS_START={[coverage]rcfile}
3334
cov: COVERAGE_OPTIONS="-p"

0 commit comments

Comments
 (0)