Skip to content

Commit

Permalink
fix: revert test utils and move close to test
Browse files Browse the repository at this point in the history
  • Loading branch information
narenaryan committed Dec 26, 2024
1 parent d284d01 commit 364e6b8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,4 @@ venv = "whispr"

[tool.pytest.ini_options]
addopts = "--cov=whispr"
pythonpath = ["src", "tests"]
pythonpath = ["src"]
28 changes: 27 additions & 1 deletion tests/test_factory.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from functools import wraps
import os
import unittest
from unittest.mock import MagicMock, patch

Expand All @@ -9,7 +11,31 @@

from whispr.factory import VaultFactory

from tests.utils import patch_env_var

def patch_env_var(var_name, var_value):
"""
Test util to patch a given environment variable safely.
:param var_name: Environment variable to patch (Ex: AWS_DEFAULT_REGION)
:param var_value: Environment variable value for testing (Ex: us-east-1)
"""

def decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
original_value = os.environ.get(var_name)
os.environ[var_name] = var_value
try:
return func(*args, **kwargs)
finally:
if original_value is not None:
os.environ[var_name] = original_value
else:
del os.environ[var_name]

return wrapper

return decorator


class FactoryTestCase(unittest.TestCase):
Expand Down

0 comments on commit 364e6b8

Please sign in to comment.