move moc_env to module
This commit is contained in:
0
pkgs/clan-cli/tests/__init__.py
Normal file
0
pkgs/clan-cli/tests/__init__.py
Normal file
14
pkgs/clan-cli/tests/environment.py
Normal file
14
pkgs/clan-cli/tests/environment.py
Normal 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)
|
||||
@@ -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"):
|
||||
|
||||
Reference in New Issue
Block a user