Skip to content

Commit 83fd893

Browse files
committed
Add test cases for commands implemented as asynchronous methods
1 parent 0695ecb commit 83fd893

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tests/test_source_cli.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import argparse
2+
import asyncio
23
import re
34
import sys
45
import time
@@ -2120,6 +2121,29 @@ def alt_cmd(self) -> None:
21202121
}
21212122

21222123

2124+
def test_cli_app_async_method_no_existing_loop():
2125+
class Command(BaseSettings):
2126+
called: bool = False
2127+
2128+
async def cli_cmd(self) -> None:
2129+
self.called = True
2130+
2131+
assert CliApp.run(Command, cli_args=[]).called
2132+
2133+
2134+
def test_cli_app_async_method_with_existing_loop():
2135+
class Command(BaseSettings):
2136+
called: bool = False
2137+
2138+
async def cli_cmd(self) -> None:
2139+
self.called = True
2140+
2141+
async def run_as_coro():
2142+
return CliApp.run(Command, cli_args=[])
2143+
2144+
assert asyncio.run(run_as_coro()).called
2145+
2146+
21232147
def test_cli_app_exceptions():
21242148
with pytest.raises(
21252149
SettingsError, match='Error: NotPydanticModel is not subclass of BaseModel or pydantic.dataclasses.dataclass'

0 commit comments

Comments
 (0)