From 2962b4456f6b1f36efb042eb713736d3806788f8 Mon Sep 17 00:00:00 2001 From: Chris Blanton Date: Fri, 22 May 2026 15:15:48 -0400 Subject: [PATCH] #898 Fix test issue caused by previously cloned fre-workflows Three seemingly independent fixes suggested by claude: 1. Add pytest configuration to forbid recursing into the 'configure_yaml_out' directory 2. In test_configure_script_yaml.py, restore HOME even if the test fails 3. In test_fre_pp_cli.py, remove the checked-out directory after the test (as well as before) --- fre/pp/tests/test_configure_script_yaml.py | 19 ++++++++++--------- fre/tests/test_fre_pp_cli.py | 16 ++++++++++------ pyproject.toml | 3 +++ 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/fre/pp/tests/test_configure_script_yaml.py b/fre/pp/tests/test_configure_script_yaml.py index 870e727b2..be8542dcf 100644 --- a/fre/pp/tests/test_configure_script_yaml.py +++ b/fre/pp/tests/test_configure_script_yaml.py @@ -44,17 +44,18 @@ def test_configure_script(): old_home = os.environ["HOME"] os.environ["HOME"] = str(Path(f"{TEST_DIR}/configure_yaml_out")) - # Set output directory - OUT_DIR = Path(f"{os.getenv('HOME')}/cylc-src/{EXPERIMENT}__{PLATFORM}__{TARGET}") - Path(OUT_DIR).mkdir(parents = True, exist_ok = True) - - # Define combined yaml - model_yaml = f"{TEST_DIR}/{TEST_YAML}" + try: + # Set output directory + OUT_DIR = Path(f"{os.getenv('HOME')}/cylc-src/{EXPERIMENT}__{PLATFORM}__{TARGET}") + Path(OUT_DIR).mkdir(parents = True, exist_ok = True) - # Invoke configure_yaml_script.py - csy.yaml_info(model_yaml, EXPERIMENT, PLATFORM, TARGET) + # Define combined yaml + model_yaml = f"{TEST_DIR}/{TEST_YAML}" - os.environ["HOME"] = old_home + # Invoke configure_yaml_script.py + csy.yaml_info(model_yaml, EXPERIMENT, PLATFORM, TARGET) + finally: + os.environ["HOME"] = old_home # Check for configuration creation and final combined yaml assert all([ Path(f"{OUT_DIR}/{EXPERIMENT}.yaml").exists(), diff --git a/fre/tests/test_fre_pp_cli.py b/fre/tests/test_fre_pp_cli.py index 1c4df7e6e..627b48716 100644 --- a/fre/tests/test_fre_pp_cli.py +++ b/fre/tests/test_fre_pp_cli.py @@ -55,12 +55,16 @@ def test_cli_fre_pp_checkout_case(): directory = os.path.expanduser("~/cylc-src")+'/FOO__BAR__BAZ' if Path(directory).exists(): shutil.rmtree(directory) - result = runner.invoke(fre.fre, args=["pp", "checkout", - "-e", "FOO", - "-p", "BAR", - "-t", "BAZ"] ) - assert all( [ result.exit_code == 0, - Path(directory).exists()] ) + try: + result = runner.invoke(fre.fre, args=["pp", "checkout", + "-e", "FOO", + "-p", "BAR", + "-t", "BAZ"] ) + assert all( [ result.exit_code == 0, + Path(directory).exists()] ) + finally: + if Path(directory).exists(): + shutil.rmtree(directory) #-- fre pp configure-yaml def test_cli_fre_pp_configure_yaml(): diff --git a/pyproject.toml b/pyproject.toml index 2664168dd..eb99ae8f7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -66,3 +66,6 @@ test = [ "pylint", "pytest", ] + +[tool.pytest.ini_options] +norecursedirs = ["configure_yaml_out", "cylc-src", ".git", "__pycache__"]