aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/pytest-lazy-fixtures/pytest_lazy_fixtures/lazy_fixture_callable.py
diff options
context:
space:
mode:
authorrobot-ydb-importer <robot-ydb-importer@yandex-team.com>2024-06-28 14:57:17 +0300
committerrobot-ydb-importer <robot-ydb-importer@yandex-team.com>2024-06-28 15:10:57 +0300
commita75ea2cde045917041437c8859477ba4323503bd (patch)
tree565ad17417cc162775e29f4b27987e2c322ddc29 /contrib/python/pytest-lazy-fixtures/pytest_lazy_fixtures/lazy_fixture_callable.py
parentd0dc9572233e6c5a1040c5eb91227066c876b832 (diff)
downloadydb-a75ea2cde045917041437c8859477ba4323503bd.tar.gz
YDB Import 604
a63e035353af5512e5e1c2789d17f495871e0007
Diffstat (limited to 'contrib/python/pytest-lazy-fixtures/pytest_lazy_fixtures/lazy_fixture_callable.py')
-rw-r--r--contrib/python/pytest-lazy-fixtures/pytest_lazy_fixtures/lazy_fixture_callable.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/contrib/python/pytest-lazy-fixtures/pytest_lazy_fixtures/lazy_fixture_callable.py b/contrib/python/pytest-lazy-fixtures/pytest_lazy_fixtures/lazy_fixture_callable.py
new file mode 100644
index 0000000000..a11b04091d
--- /dev/null
+++ b/contrib/python/pytest-lazy-fixtures/pytest_lazy_fixtures/lazy_fixture_callable.py
@@ -0,0 +1,33 @@
+from typing import Callable, Optional, Union
+
+import pytest
+
+from .lazy_fixture import LazyFixtureWrapper
+
+
+class LazyFixtureCallableWrapper(LazyFixtureWrapper):
+ _func: Optional[Callable]
+ args: tuple
+ kwargs: dict
+
+ def __init__(self, func_or_name: Union[Callable, str], *args, **kwargs):
+ if callable(func_or_name):
+ self._func = func_or_name
+ self.name = func_or_name.__name__
+ else:
+ self.name = func_or_name
+ self._func = None
+ self.args = args
+ self.kwargs = kwargs
+
+ def get_func(self, request: pytest.FixtureRequest) -> Callable:
+ func = self._func
+ if func is None:
+ func = self.load_fixture(request)
+ assert callable(func)
+ return func
+
+
+def lfc(name: Union[Callable, str], *args, **kwargs) -> LazyFixtureCallableWrapper:
+ """lfc is a lazy fixture callable."""
+ return LazyFixtureCallableWrapper(name, *args, **kwargs)