diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py index 09dcbcd40ad..924b1295998 100644 --- a/tests/unit/conftest.py +++ b/tests/unit/conftest.py @@ -82,36 +82,36 @@ def _tmp_run_dir(tmp_path: Path, monkeypatch: pytest.MonkeyPatch): # Or: cylc_run_dir = tmp_run_dir() """ + cylc_run_dir = tmp_path / 'cylc-run' + cylc_run_dir.mkdir(exist_ok=True) + monkeypatch.setattr('cylc.flow.pathutil._CYLC_RUN_DIR', cylc_run_dir) + def __tmp_run_dir( id_: Optional[str] = None, installed: bool = False, named: bool = False ) -> Path: - nonlocal tmp_path - nonlocal monkeypatch - cylc_run_dir = tmp_path / 'cylc-run' - cylc_run_dir.mkdir(exist_ok=True) - monkeypatch.setattr('cylc.flow.pathutil._CYLC_RUN_DIR', cylc_run_dir) - if id_: - run_dir = cylc_run_dir.joinpath(id_) - run_dir.mkdir(parents=True, exist_ok=True) - (run_dir / WorkflowFiles.FLOW_FILE).touch(exist_ok=True) - (run_dir / WorkflowFiles.Service.DIRNAME).mkdir(exist_ok=True) - if run_dir.name.startswith('run'): - unlink_runN(run_dir.parent) - link_runN(run_dir) - if installed: - if named: - if len(Path(id_).parts) < 2: - raise ValueError("Named run requires two-level id_") - (run_dir.parent / WorkflowFiles.Install.DIRNAME).mkdir( - exist_ok=True) - else: - (run_dir / WorkflowFiles.Install.DIRNAME).mkdir( - exist_ok=True) - - return run_dir - return cylc_run_dir + if not id_: + return cylc_run_dir + + run_dir = cylc_run_dir.joinpath(id_) + run_dir.mkdir(parents=True, exist_ok=True) + (run_dir / WorkflowFiles.FLOW_FILE).touch(exist_ok=True) + (run_dir / WorkflowFiles.Service.DIRNAME).mkdir(exist_ok=True) + if run_dir.name.startswith('run'): + unlink_runN(run_dir.parent) + link_runN(run_dir) + if installed: + if named: + if len(Path(id_).parts) < 2: + raise ValueError("Named run requires two-level id_") + (run_dir.parent / WorkflowFiles.Install.DIRNAME).mkdir( + exist_ok=True) + else: + (run_dir / WorkflowFiles.Install.DIRNAME).mkdir(exist_ok=True) + + return run_dir + return __tmp_run_dir diff --git a/tests/unit/test_clean.py b/tests/unit/test_clean.py index a0c0ccdda1e..2a67daf4bf4 100644 --- a/tests/unit/test_clean.py +++ b/tests/unit/test_clean.py @@ -182,7 +182,6 @@ def test_init_clean__no_dir( ) -> None: """Test init_clean() when the run dir doesn't exist""" caplog.set_level(logging.INFO, CYLC_LOG) - tmp_run_dir() mock_clean = monkeymock('cylc.flow.clean.clean') mock_remote_clean = monkeymock('cylc.flow.clean.remote_clean') @@ -754,7 +753,6 @@ def test_clean__targeted( """ # --- Setup --- caplog.set_level(logging.DEBUG, CYLC_LOG) - tmp_run_dir() id_ = 'foo/bar' run_dir: Path files_to_delete: List[str] diff --git a/tests/unit/test_install.py b/tests/unit/test_install.py index 3230eea5d87..b15ba3286f8 100644 --- a/tests/unit/test_install.py +++ b/tests/unit/test_install.py @@ -84,7 +84,6 @@ def test_install_workflow__max_depth( prevent_symlinking, ): """Test that trying to install beyond max depth fails.""" - tmp_run_dir() src_dir = tmp_src_dir('bar') if err_expected: with pytest.raises(WorkflowFilesError) as exc_info: @@ -138,7 +137,6 @@ def test_install_workflow__symlink_target_exists( already exists.""" id_ = 'smeagol' src_dir: Path = tmp_src_dir(id_) - tmp_run_dir() sym_run = tmp_path / 'sym-run' sym_log = tmp_path / 'sym-log' mock_glbl_cfg( @@ -544,7 +542,7 @@ def test_validate_source_dir(tmp_run_dir: Callable, tmp_src_dir: Callable): assert "exists in source directory" in str(exc_info.value) -def test_install_workflow_failif_name_name(tmp_src_dir): +def test_install_workflow_failif_name_name(tmp_src_dir, tmp_run_dir): """If a run_name is given validate_workflow_name is called on the workflow and the run name in combination. """ @@ -560,7 +558,7 @@ def test_install_workflow_failif_name_name(tmp_src_dir): install_workflow(src_dir, workflow_name='foo', run_name='bar?') -def test_install_workflow_failif_reserved_name(tmp_src_dir): +def test_install_workflow_failif_reserved_name(tmp_src_dir, tmp_run_dir): """Reserved names cause install validation failure. n.b. manually defined to avoid test dependency on workflow_files.