From 1e3e97cabd1cae4f8e134217a33324e3dda055d2 Mon Sep 17 00:00:00 2001 From: Tim Pillinger <26465611+wxtim@users.noreply.github.com> Date: Thu, 25 Jan 2024 16:35:42 +0000 Subject: [PATCH] Mock only a single method of the rose config object. (#291) Use a real RoseConfig to avoid need to mock objects. --- tests/functional/test_rose_stem.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/functional/test_rose_stem.py b/tests/functional/test_rose_stem.py index c25df3e1..b50d4782 100644 --- a/tests/functional/test_rose_stem.py +++ b/tests/functional/test_rose_stem.py @@ -73,7 +73,6 @@ from shlex import split from types import SimpleNamespace from uuid import uuid4 -from unittest.mock import MagicMock from cylc.flow.pathutil import get_workflow_run_dir from cylc.flow.hostuserutil import get_host @@ -118,13 +117,14 @@ def mock_global_cfg(monkeymodule): conf: A fake rose global config as a string. """ def _inner(target, conf): - """Mock a config object with a config node.""" - node = ConfigLoader().load(StringIO(conf)) - - # Create a fake class imitating ConfigTree with .get_conf method: - config = MagicMock(spec=['get_conf'], get_conf=lambda: node) + """Get the ResourceLocator.default and patch its get_conf method + """ + obj = ResourceLocator.default() + monkeymodule.setattr( + obj, 'get_conf', lambda: ConfigLoader().load(StringIO(conf)) + ) - monkeymodule.setattr(target, lambda *_, **__: config) + monkeymodule.setattr(target, lambda *_, **__: obj) yield _inner