move moc_env to module

This commit is contained in:
Jörg Thalheim
2023-07-26 15:14:29 +02:00
parent a61d0c5a42
commit b4ba9c70cd
3 changed files with 17 additions and 14 deletions

View File

View File

@@ -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)

View File

@@ -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"):