Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

De-flake tests (Avoid cleanup errors when using -n > 1) #333

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/
wxtim marked this conversation as resolved.
Show resolved Hide resolved
wxtim marked this conversation as resolved.
Show resolved Hide resolved

- 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