Skip to content

Commit 415a2bf

Browse files
committed
Fix SiteDir fixture to properly patch sys.path in one place, encapsulating concern and avoiding adding duplicate entries. Fixes #61.
1 parent a14e095 commit 415a2bf

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

importlib_metadata/tests/fixtures.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@
2424
@contextlib.contextmanager
2525
def tempdir():
2626
tmpdir = tempfile.mkdtemp()
27-
sys.path[:0] = [tmpdir]
2827
try:
2928
yield pathlib.Path(tmpdir)
3029
finally:
31-
sys.path.remove(tmpdir)
3230
shutil.rmtree(tmpdir)
3331

3432

@@ -55,7 +53,10 @@ class SiteDir:
5553
def site_dir():
5654
with tempdir() as tmp:
5755
sys.path[:0] = [str(tmp)]
58-
yield tmp
56+
try:
57+
yield tmp
58+
finally:
59+
sys.path.remove(str(tmp))
5960

6061
def setUp(self):
6162
self.fixtures = ExitStack()

0 commit comments

Comments
 (0)