aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/pytest-lazy-fixtures/pytest_lazy_fixtures/lazy_fixture_callable.py
diff options
context:
space:
mode:
authorAlexander Smirnov <alex@ydb.tech>2024-07-08 15:54:05 +0000
committerAlexander Smirnov <alex@ydb.tech>2024-07-08 15:54:05 +0000
commitfc7be18c76af2e700641f3598c4856baeef1428e (patch)
tree11dbca45eb321c3a4dd08b12152acc6ef5dd3fa9 /contrib/python/pytest-lazy-fixtures/pytest_lazy_fixtures/lazy_fixture_callable.py
parentec0e7ed6da6fb317741fd8468602949a1362eca5 (diff)
parentc92cb9d3a19331916f0c274d80e67f02a62caa9b (diff)
downloadydb-fc7be18c76af2e700641f3598c4856baeef1428e.tar.gz
Merge branch 'rightlib' into mergelibs-240708-1553
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)