diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d1bc273d..a00f1c77 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -71,7 +71,7 @@ jobs: run: make test e2e-test: - runs-on: ubuntu-latest + runs-on: 'ubuntu-24.04' permissions: contents: read steps: diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index b0867dfb..8cf5c094 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -33,7 +33,7 @@ concurrency: jobs: publish-image: - runs-on: 'ubuntu-latest' + runs-on: 'ubuntu-24.04' permissions: contents: read # kics-scan ignore-line diff --git a/tests/conftest.py b/tests/conftest.py index aa0de784..b170dcf2 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -5,9 +5,8 @@ """Common test fixtures.""" import argparse -import logging import pathlib -from tempfile import TemporaryDirectory +import tempfile from typing import Any, Dict, Generator, Tuple, TypeVar import pytest @@ -36,23 +35,19 @@ @pytest.fixture(scope="function") def tmp_repo() -> YieldFixture[Tuple[str, Repo]]: """Create a temporary git repository with an initialized trestle workspace root""" - with TemporaryDirectory(prefix=_TEST_PREFIX) as tmpdir: - tmp_path = pathlib.Path(tmpdir) - repo: Repo = repo_setup(tmp_path) - remote_url = "http://localhost:8080/test.git" - repo.create_remote("origin", url=remote_url) - yield tmpdir, repo - - try: - clean(tmpdir, repo) - except Exception as e: - logging.error(f"Failed to clean up temporary git repository: {e}") + tmpdir = tempfile.mkdtemp(prefix=_TEST_PREFIX) + tmp_path = pathlib.Path(tmpdir) + repo: Repo = repo_setup(tmp_path) + remote_url = "http://localhost:8080/test.git" + repo.create_remote("origin", url=remote_url) + yield tmpdir, repo + clean(tmpdir, repo) @pytest.fixture(scope="function") def tmp_trestle_dir() -> YieldFixture[str]: """Create an initialized temporary trestle directory""" - with TemporaryDirectory(prefix=_TEST_PREFIX) as tmpdir: + with tempfile.TemporaryDirectory(prefix=_TEST_PREFIX) as tmpdir: tmp_path = pathlib.Path(tmpdir) try: args = argparse.Namespace( diff --git a/tests/e2e/e2e_testutils.py b/tests/e2e/e2e_testutils.py index 72ec2bc3..d11acf1f 100644 --- a/tests/e2e/e2e_testutils.py +++ b/tests/e2e/e2e_testutils.py @@ -144,7 +144,8 @@ def build_test_command( E2ETestRunner.TRESTLEBOT_TEST_POD_NAME, "--entrypoint", f"trestlebot-{command_name}", - "--rm", + "--restart", + "never", ] # Add mounts diff --git a/tests/trestlebot/tasks/test_sync_upstream_task.py b/tests/trestlebot/tasks/test_sync_upstream_task.py index 70a5cb8a..88718a36 100644 --- a/tests/trestlebot/tasks/test_sync_upstream_task.py +++ b/tests/trestlebot/tasks/test_sync_upstream_task.py @@ -104,9 +104,8 @@ def test_sync_upstream_invalid_git( ) -> None: """Test sync upstreams task with invalid git source""" tmp_repo_path, _ = tmp_repo - # Now remove the git repo - shutil.rmtree(tmp_repo_path) - sync = SyncUpstreamsTask(tmp_trestle_dir, [f"{tmp_repo_path}@main"]) + new_path = f"{tmp_repo_path}1" + sync = SyncUpstreamsTask(tmp_trestle_dir, [f"{new_path}@main"]) with pytest.raises( TaskException, match="Git error occurred while fetching content from .*" ): diff --git a/tests/trestlebot/test_github.py b/tests/trestlebot/test_github.py index 73b09845..10b7de47 100644 --- a/tests/trestlebot/test_github.py +++ b/tests/trestlebot/test_github.py @@ -13,7 +13,7 @@ from git.repo import Repo from responses import GET, POST, RequestsMock -from tests.testutils import JSON_TEST_DATA_PATH, clean +from tests.testutils import JSON_TEST_DATA_PATH from trestlebot.github import GitHub, GitHubActionsResultsReporter, set_output from trestlebot.provider import GitProviderException from trestlebot.reporter import BotResults @@ -50,8 +50,6 @@ def test_parse_repository_integration(tmp_repo: Tuple[str, Repo]) -> None: assert owner == "test" assert repo_name == "repo" - clean(repo_path, repo) - def test_parse_repository_with_incorrect_name() -> None: """Test an invalid url input""" diff --git a/tests/trestlebot/test_gitlab.py b/tests/trestlebot/test_gitlab.py index a2b6b85e..6608776a 100644 --- a/tests/trestlebot/test_gitlab.py +++ b/tests/trestlebot/test_gitlab.py @@ -12,7 +12,6 @@ from gitlab.exceptions import GitlabAuthenticationError, GitlabCreateError from responses import GET, POST, RequestsMock -from tests.testutils import clean from trestlebot.gitlab import GitLab, GitLabCIResultsReporter from trestlebot.provider import GitProviderException from trestlebot.reporter import BotResults @@ -86,8 +85,6 @@ def test_parse_repository_integration(tmp_repo: Tuple[str, Repo]) -> None: assert owner == "test" assert repo_name == "repo" - clean(repo_path, repo) - def test_parse_repository_with_incorrect_name() -> None: """Test an invalid url input"""