Skip to content

Commit 2d361c9

Browse files
committed
Added string annotation testing
1 parent 7faaaeb commit 2d361c9

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tests/test_routing/test_background_tasks.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ def check_background_task_working(tasks: BackgroundTasks):
3737
return "testing background tasks"
3838

3939

40+
@router.get("/background-task-with-string-annotation")
41+
def check_background_task_working_with_string_annotation(tasks: "BackgroundTasks"):
42+
tasks.add_task(background_task_2)
43+
tasks.add_task(background_task_1)
44+
45+
return "testing background tasks"
46+
47+
4048
def test_background_tasks_works():
4149
global background_task_results
4250
background_task_results = {}
@@ -65,3 +73,19 @@ def test_any_existing_background_task():
6573
"background_task_2": "Called",
6674
"background_task_3": "Called",
6775
}
76+
77+
78+
def test_any_existing_background_task_with_string_annotation():
79+
global background_task_results
80+
background_task_results = {}
81+
82+
client = Test.create_test_module(modules=[ModuleSample]).get_test_client()
83+
res = client.get("/background-task-with-string-annotation")
84+
assert res.status_code == 200
85+
assert res.text == '"testing background tasks"'
86+
87+
assert background_task_results == {
88+
"background_task_1": "Called",
89+
"background_task_2": "Called",
90+
"background_task_3": "Called",
91+
}

0 commit comments

Comments
 (0)