Skip to content

Commit

Permalink
fix(tests): ensure only mocked system site is used
Browse files Browse the repository at this point in the history
Previously, on systems where there existed multiple system-site
locations the `test_system_site_packages` test case failed due to it
incorrectly assuming only one site needed removal when patching the
environment's `sys_path`. This change ensures all paths outside the
`tmp_path` is ignored.
  • Loading branch information
abn committed Jan 5, 2025
1 parent a5887d8 commit fc2faeb
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions tests/repositories/test_installed_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,11 @@ def test_system_site_packages(
shutil.copytree(site_purelib / standard_dist_info, env.purelib / standard_dist_info)
orig_sys_path = env.sys_path
if with_system_site_packages:
# on some environments, there could be multiple system-site, filter out those and inject our test site
mocker.patch(
"poetry.utils.env.virtual_env.VirtualEnv.sys_path",
orig_sys_path[:-1] + [str(site_path)],
[p for p in orig_sys_path if p.startswith(str(tmp_path))]
+ [str(site_path)],
)
mocker.patch(
"poetry.utils.env.generic_env.GenericEnv.get_paths",
Expand All @@ -449,9 +451,10 @@ def test_system_site_packages(
installed_repository = InstalledRepository.load(env)

expected_system_site_packages = {"cleo"} if with_system_site_packages else set()
expected_packages = {"standard"} | expected_system_site_packages
if platform.system() == "FreeBSD":
expected_packages = {"standard"}
if platform.system() == "FreeBSD" and not with_system_site_packages:
expected_packages.add("sqlite3")
expected_packages |= expected_system_site_packages
assert {p.name for p in installed_repository.packages} == expected_packages
assert {
p.name for p in installed_repository.system_site_packages
Expand Down

0 comments on commit fc2faeb

Please sign in to comment.