Skip to content

Commit

Permalink
fix(test): fix pyfakefs real_directory errors
Browse files Browse the repository at this point in the history
  • Loading branch information
lengau committed Jun 12, 2024
1 parent 488d837 commit dc8e9d4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions tests/integration/services/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def service_factory(
# Allow access to the real venv library path.
# This is necessary because certifi lazy-loads the certificate file.
for python_path in sys.path:
if not python_path:
continue
with contextlib.suppress(OSError):
fs.add_real_directory(python_path)

Expand Down
10 changes: 7 additions & 3 deletions tests/integration/services/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#
# For further info, check https://github.com/canonical/charmcraft
"""Tests for package service."""
import contextlib
import datetime
import pathlib

Expand Down Expand Up @@ -50,7 +51,8 @@ def package_service(fake_path, service_factory, default_build_plan):
@freezegun.freeze_time(datetime.datetime(2020, 3, 14, 0, 0, 0, tzinfo=datetime.timezone.utc))
def test_write_metadata(monkeypatch, fs, package_service, project_path):
monkeypatch.setattr(charmcraft, "__version__", "3.0-test-version")
fs.add_real_directory(project_path)
with contextlib.suppress(FileExistsError):
fs.add_real_directory(project_path)
test_prime_dir = pathlib.Path("/prime")
fs.create_dir(test_prime_dir)
expected_prime_dir = project_path / "prime"
Expand Down Expand Up @@ -79,7 +81,8 @@ def test_overwrite_metadata(monkeypatch, fs, package_service, project_path):
Regression test for https://github.com/canonical/charmcraft/issues/1654
"""
monkeypatch.setattr(charmcraft, "__version__", "3.0-test-version")
fs.add_real_directory(project_path)
with contextlib.suppress(FileExistsError):
fs.add_real_directory(project_path)
test_prime_dir = pathlib.Path("/prime")
fs.create_dir(test_prime_dir)
expected_prime_dir = project_path / "prime"
Expand All @@ -104,7 +107,8 @@ def test_no_overwrite_reactive_metadata(monkeypatch, fs, package_service):
"""
monkeypatch.setattr(charmcraft, "__version__", "3.0-test-version")
project_path = pathlib.Path(__file__).parent / "sample_projects" / "basic-reactive"
fs.add_real_directory(project_path)
with contextlib.suppress(FileExistsError):
fs.add_real_directory(project_path)
test_prime_dir = pathlib.Path("/prime")
fs.create_dir(test_prime_dir)
test_stage_dir = pathlib.Path("/stage")
Expand Down

0 comments on commit dc8e9d4

Please sign in to comment.