Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
43 changes: 43 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# SPDX-FileCopyrightText: 2026 Idiap Research Institute <contact@idiap.ch>
#
# SPDX-License-Identifier: GPL-3.0-or-later

import contextlib
import os
import tempfile

from collections.abc import Iterator
from pathlib import Path

import pytest

from click.testing import CliRunner


class Runner(CliRunner):
"""A CliRunner with the ``isolated_filesystem`` that Click deprecated.

Click 9.0 removes ``CliRunner.isolated_filesystem``, advising to use a
temporary directory instead. The tests run commands that use relative paths,
so this keeps the same behaviour: run in a new temporary directory.
"""

@contextlib.contextmanager
def isolated_filesystem(
self, temp_dir: str | os.PathLike[str] | None = None
) -> Iterator[str]:
"""Change to a new temporary directory (created in ``temp_dir``) until the
end of the ``with`` block, and yield its path.
"""
cwd = Path.cwd()
with tempfile.TemporaryDirectory(dir=temp_dir) as path:
os.chdir(path)
try:
yield path
finally:
os.chdir(cwd)


@pytest.fixture
def runner():
return Runner()
7 changes: 0 additions & 7 deletions tests/test_gridtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

import pytest

from click.testing import CliRunner

from gridtk.__main__ import cli
from gridtk.tools import (
add_default_dep_type,
Expand All @@ -24,11 +22,6 @@
)


@pytest.fixture
def runner():
return CliRunner()


def _sbatch_output(job_id):
return f"Submitted batch job {job_id}\n"

Expand Down
7 changes: 0 additions & 7 deletions tests/test_guard.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,10 @@

import pytest

from click.testing import CliRunner

from gridtk import guard
from gridtk.cli import cli


@pytest.fixture
def runner():
return CliRunner()


def _git(repo: Path, *args: str) -> str:
return subprocess.run(
[
Expand Down
Loading