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
5 changes: 1 addition & 4 deletions injection/testing/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from contextlib import ContextDecorator
from typing import ContextManager, Final

from injection import mod
Expand All @@ -22,7 +21,5 @@
test_singleton = mod(_TEST_PROFILE_NAME).singleton


def load_test_profile(
*other_profile_names: str,
) -> ContextManager[None] | ContextDecorator:
def load_test_profile(*other_profile_names: str) -> ContextManager[None]:
return load_profile(_TEST_PROFILE_NAME, *other_profile_names)
5 changes: 1 addition & 4 deletions injection/testing/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from contextlib import ContextDecorator
from typing import ContextManager

import injection as _
Expand All @@ -9,9 +8,7 @@ test_constant = _.constant
test_injectable = _.injectable
test_singleton = _.singleton

def load_test_profile(
*additional_names: str,
) -> ContextManager[None] | ContextDecorator:
def load_test_profile(*additional_names: str) -> ContextManager[None]:
"""
Context manager or decorator for temporary use test module.
"""
14 changes: 6 additions & 8 deletions injection/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections.abc import Callable, Iterator
from contextlib import ContextDecorator, contextmanager
from contextlib import contextmanager
from importlib import import_module
from pkgutil import walk_packages
from types import ModuleType as PythonModule
Expand All @@ -10,11 +10,7 @@
__all__ = ("load_packages", "load_profile")


def load_profile(
name: str,
/,
*other_profile_names: str,
) -> ContextManager[None] | ContextDecorator:
def load_profile(name: str, /, *other_profile_names: str) -> ContextManager[None]:
"""
Injection module initialization function based on profile name.
A profile name is equivalent to an injection module name.
Expand All @@ -27,12 +23,14 @@ def load_profile(

target = mod().unlock().init_modules(*modules)

del module, modules

@contextmanager
def teardown() -> Iterator[None]:
def cleaner() -> Iterator[None]:
yield
target.unlock().init_modules()

return teardown()
return cleaner()


def load_packages(
Expand Down
120 changes: 60 additions & 60 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ warn_required_dynamic_aliases = true
[tool.pytest.ini_options]
python_files = "test_*.py"
addopts = "-p no:warnings --tb=short --cov=./ --cov-report term-missing:skip-covered"
asyncio_default_fixture_loop_scope = "session"
asyncio_mode = "auto"
testpaths = "**/tests/"

Expand Down