diff --git a/tests/conftest.py b/tests/conftest.py index 7c46c04..ff8d071 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -26,6 +26,7 @@ from uuid import uuid4 import pytest +from xdist import is_xdist_controller from cylc.flow import __version__ as CYLC_VERSION from cylc.flow.option_parsers import Options @@ -376,12 +377,15 @@ def mod_test_dir(request, ses_test_dir): path = Path(ses_test_dir, request.module.__name__) path.mkdir(exist_ok=True) yield path - if _pytest_passed(request): - # test passed -> remove all files - rmtree(path, ignore_errors=False) - else: - # test failed -> remove the test dir if empty - _rm_if_empty(path) + # Only clean up if this is the xdist controller process: + if is_xdist_controller(request): + if _pytest_passed(request): + # test passed -> remove all files + rmtree(path, ignore_errors=False) + + else: + # test failed -> remove the test dir if empty + _rm_if_empty(path) @pytest.fixture @@ -390,12 +394,13 @@ def test_dir(request, mod_test_dir): path = Path(mod_test_dir, request.function.__name__) path.mkdir(parents=True, exist_ok=True) yield path - if _pytest_passed(request): - # test passed -> remove all files - rmtree(path, ignore_errors=False) - else: - # test failed -> remove the test dir if empty - _rm_if_empty(path) + if is_xdist_controller(request): + if _pytest_passed(request): + # test passed -> remove all files + rmtree(path, ignore_errors=False) + else: + # test failed -> remove the test dir if empty + _rm_if_empty(path) @pytest.fixture diff --git a/tests/functional/test_reinstall.py b/tests/functional/test_reinstall.py index 7c7b06b..4fae2fa 100644 --- a/tests/functional/test_reinstall.py +++ b/tests/functional/test_reinstall.py @@ -37,6 +37,7 @@ from cylc.flow.install import reinstall_workflow from cylc.flow.pathutil import get_workflow_run_dir import pytest +from xdist import is_xdist_controller from cylc.rose.utilities import ( ROSE_ORIG_HOST_INSTALLED_OVERRIDE_STRING as ROHIOS, @@ -72,7 +73,7 @@ def fixture_provide_flow(tmp_path_factory, request): 'flowpath': flowpath, 'srcpath': srcpath } - if not request.session.testsfailed: + if is_xdist_controller(request) and not request.session.testsfailed: shutil.rmtree(srcpath) shutil.rmtree(flowpath) diff --git a/tests/functional/test_reinstall_clean.py b/tests/functional/test_reinstall_clean.py index e42617b..47879d1 100644 --- a/tests/functional/test_reinstall_clean.py +++ b/tests/functional/test_reinstall_clean.py @@ -35,6 +35,7 @@ from cylc.flow.hostuserutil import get_host from cylc.flow.pathutil import get_workflow_run_dir import pytest +from xdist import is_xdist_controller from cylc.rose.utilities import ( ROSE_ORIG_HOST_INSTALLED_OVERRIDE_STRING as ROHIOS, @@ -70,7 +71,10 @@ def fixture_provide_flow(tmp_path_factory, request): 'flowpath': flowpath, 'srcpath': srcpath } - if not request.session.testsfailed: + if ( + is_xdist_controller(request) + and not request.session.testsfailed + ): shutil.rmtree(srcpath) shutil.rmtree(flowpath)