diff --git a/pkgs/clan-cli/tests/__init__.py b/pkgs/clan-cli/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pkgs/clan-cli/tests/environment.py b/pkgs/clan-cli/tests/environment.py new file mode 100644 index 0000000..24226db --- /dev/null +++ b/pkgs/clan-cli/tests/environment.py @@ -0,0 +1,14 @@ +import os +from contextlib import contextmanager +from typing import Iterator + + +@contextmanager +def mock_env(**environ: str) -> Iterator[None]: + original_environ = dict(os.environ) + os.environ.update(environ) + try: + yield + finally: + os.environ.clear() + os.environ.update(original_environ) diff --git a/pkgs/clan-cli/tests/test_clan_ssh.py b/pkgs/clan-cli/tests/test_clan_ssh.py index e864a18..628bc0e 100644 --- a/pkgs/clan-cli/tests/test_clan_ssh.py +++ b/pkgs/clan-cli/tests/test_clan_ssh.py @@ -1,7 +1,5 @@ -import os import sys -from contextlib import contextmanager -from typing import Iterator, Union +from typing import Union import pytest import pytest_subprocess.fake_process @@ -9,6 +7,8 @@ from pytest_subprocess import utils import clan_cli.ssh +from .environment import mock_env + def test_no_args( capsys: pytest.CaptureFixture, monkeypatch: pytest.MonkeyPatch @@ -20,17 +20,6 @@ def test_no_args( assert captured.err.startswith("usage:") -@contextmanager -def mock_env(**environ: str) -> Iterator[None]: - original_environ = dict(os.environ) - os.environ.update(environ) - try: - yield - finally: - os.environ.clear() - os.environ.update(original_environ) - - # using fp fixture from pytest-subprocess def test_ssh_no_pass(fp: pytest_subprocess.fake_process.FakeProcess) -> None: with mock_env(CLAN_FLAKE="/mocked-flake"):