Skip to content

Commit

Permalink
tests.only clean up tests in controller worker to prevent cleanup err…
Browse files Browse the repository at this point in the history
…ors.
  • Loading branch information
wxtim committed Jun 26, 2024
1 parent 5d16afd commit d1f5cab
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
- name: Test
run: |
pytest -n 5 tests/
pytest tests/
- name: Doctest
run: |
Expand Down
29 changes: 17 additions & 12 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion tests/functional/test_reinstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Expand Down
6 changes: 5 additions & 1 deletion tests/functional/test_reinstall_clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit d1f5cab

Please sign in to comment.