From 1367df2d55719c958d3b1cbfd0a7e3d4c0b99afd Mon Sep 17 00:00:00 2001 From: "Jason C. Nucciarone" Date: Tue, 16 Jul 2024 15:17:57 -0400 Subject: [PATCH] fix(tests): correctly patch filesystem on python 3.8 Signed-off-by: Jason C. Nucciarone --- tests/unit/test_juju_systemd_notices.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/unit/test_juju_systemd_notices.py b/tests/unit/test_juju_systemd_notices.py index 86bb32a6..4ce2dfb1 100644 --- a/tests/unit/test_juju_systemd_notices.py +++ b/tests/unit/test_juju_systemd_notices.py @@ -7,6 +7,7 @@ import argparse import subprocess import unittest +from pathlib import Path from unittest.mock import AsyncMock, patch from charms.operator_libs_linux.v0.juju_systemd_notices import ( @@ -98,7 +99,12 @@ def test_generate_hooks(self, mock_exists, _) -> None: def test_generate_config(self, mock_exists) -> None: """Test that watch configuration file is generated correctly.""" with Patcher() as patcher: - patcher.fs.create_file("no-disk-path/watch.yaml") + # Set charm_dir to "/" because mocked charm_dir default + # `no-disk-path` does not exist within the fake filesystem. + # Tried creating `no-disk-path` in the fake filesystem, but + # the mocked objects could not find it. + self.harness.charm.framework.charm_dir = Path("/") + patcher.fs.create_file("watch.yaml") # Scenario 1 - Generate success but no pre-existing watch configuration. mock_exists.return_value = False