Skip to content

Commit c64cc77

Browse files
Improve startup test cases, to ensure startup handlers are called
1 parent 95b95d9 commit c64cc77

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

tests/test_decorators.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,20 +1576,25 @@ def test_multiple_cli(ints: hug.types.Multiple[int]() = []):
15761576
assert hug.test.cli(test_multiple_cli, ints=["1", "2", "3"]) == [1, 2, 3]
15771577

15781578

1579-
def test_startup():
1579+
def test_startup(hug_api):
15801580
"""Test to ensure hug startup decorators work as expected"""
1581+
happened_on_startup = []
15811582

1582-
@hug.startup()
1583+
@hug.startup(api=hug_api)
15831584
def happens_on_startup(api):
1584-
pass
1585+
happened_on_startup.append("non-async")
15851586

1586-
@hug.startup()
1587+
@hug.startup(api=hug_api)
15871588
@asyncio.coroutine
15881589
def async_happens_on_startup(api):
1589-
pass
1590+
happened_on_startup.append("async")
1591+
1592+
assert happens_on_startup in hug_api.startup_handlers
1593+
assert async_happens_on_startup in hug_api.startup_handlers
15901594

1591-
assert happens_on_startup in api.startup_handlers
1592-
assert async_happens_on_startup in api.startup_handlers
1595+
hug_api._ensure_started()
1596+
assert "async" in happened_on_startup
1597+
assert "non-async" in happened_on_startup
15931598

15941599

15951600
@pytest.mark.skipif(sys.platform == "win32", reason="Currently failing on Windows build")

0 commit comments

Comments
 (0)