From 30049b87701e9b39de5c52b81be982c24bb9c84a Mon Sep 17 00:00:00 2001 From: mic1on Date: Wed, 10 Jul 2024 21:57:24 +0800 Subject: [PATCH] feat: add attribute `__step_params__` --- src/onestep/onestep.py | 1 + tests/test_step_params.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 tests/test_step_params.py diff --git a/src/onestep/onestep.py b/src/onestep/onestep.py index 6d3cc16..96b54c3 100644 --- a/src/onestep/onestep.py +++ b/src/onestep/onestep.py @@ -241,6 +241,7 @@ def __init__(self, } def __call__(self, func, *_args, **_kwargs): + func.__step_params__ = self.params if iscoroutinefunction(func) or isasyncgenfunction(func): os = AsyncOneStep(fn=func, **self.params) else: diff --git a/tests/test_step_params.py b/tests/test_step_params.py new file mode 100644 index 0000000..da441bc --- /dev/null +++ b/tests/test_step_params.py @@ -0,0 +1,20 @@ +import pytest + +from onestep import step +from onestep.broker import MemoryBroker + + +@pytest.fixture +def broker(): + return MemoryBroker() + + +def test_func(broker): + + @step(from_broker=broker, name="do_some_thing") + def do_some_thing(message): + ... + assert do_some_thing.__step_params__ is not None + + assert do_some_thing.__step_params__["from_broker"] == broker + assert do_some_thing.__step_params__["name"] == "do_some_thing" \ No newline at end of file