Skip to content

Commit

Permalink
Add test for stacked decorators
Browse files Browse the repository at this point in the history
Signed-off-by: Bernhard Stadlbauer <[email protected]>
  • Loading branch information
Bernhard Stadlbauer committed Dec 17, 2021
1 parent 0350598 commit 43bf75b
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tests/flytekit/unit/core/test_wrapping.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from functools import wraps

from flytekit import task, workflow


Expand All @@ -9,6 +11,45 @@ def my_task(a: int) -> int:
assert my_task.__wrapped__ == my_task._task_function


def test_stacked_decorators():
def task_decorator_1(fn):
@wraps(fn)
def wrapper(*args, **kwargs):
print("running task_decorator_1")
return fn(*args, **kwargs)

return wrapper

def task_decorator_2(fn):
@wraps(fn)
def wrapper(*args, **kwargs):
print("running task_decorator_2")
return fn(*args, **kwargs)

return wrapper

def task_decorator_3(fn):
@wraps(fn)
def wrapper(*args, **kwargs):
print("running task_decorator_3")
return fn(*args, **kwargs)

return wrapper

@task
@task_decorator_1
@task_decorator_2
@task_decorator_3
def my_task(x: int) -> int:
"""Some function doc"""
print("running my_task")
return x + 1

assert my_task.__wrapped__.__doc__ == "Some function doc"
assert my_task.__wrapped__ == my_task._task_function
assert my_task(x=10) == 11


def test_wf_correctly_wrapped():
@workflow
def my_workflow(a: int) -> int:
Expand Down

0 comments on commit 43bf75b

Please sign in to comment.