Skip to content

Commit 5668b53

Browse files
committed
fixed tests
1 parent 22a2c03 commit 5668b53

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

src/fastapi_cli/cli.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ def _run(
6363
is_factory: bool = False,
6464
) -> None:
6565
try:
66-
use_uvicorn_app = get_import_string(path=path, app_name=app, is_factory=is_factory)
66+
use_uvicorn_app = get_import_string(
67+
path=path, app_name=app, is_factory=is_factory
68+
)
6769
except FastAPICLIException as e:
6870
logger.error(str(e))
6971
raise typer.Exit(code=1) from None
@@ -85,6 +87,7 @@ def _run(
8587
padding=(1, 2),
8688
style="green",
8789
)
90+
print(Padding(panel, 1))
8891
if not uvicorn:
8992
raise FastAPICLIException(
9093
"Could not import Uvicorn, try running 'pip install uvicorn'"
@@ -148,7 +151,9 @@ def dev(
148151
] = True,
149152
factory: Annotated[
150153
bool,
151-
typer.Option(help="Treat [bold]path[bold] as an application factory, i.e. a () -> <ASGI app> callable.")
154+
typer.Option(
155+
help="Treat [bold]path[/bold] as an application factory, i.e. a () -> <ASGI app> callable."
156+
),
152157
] = False,
153158
) -> Any:
154159
"""
@@ -242,7 +247,9 @@ def run(
242247
] = True,
243248
factory: Annotated[
244249
bool,
245-
typer.Option(help="Treat [bold]path[bold] as an application factory, i.e. a () -> <ASGI app> callable.")
250+
typer.Option(
251+
help="Treat [bold]path[/bold] as an application factory, i.e. a () -> <ASGI app> callable."
252+
),
246253
] = False,
247254
) -> Any:
248255
"""
@@ -280,7 +287,7 @@ def run(
280287
app=app,
281288
command="run",
282289
proxy_headers=proxy_headers,
283-
is_factory=factory
290+
is_factory=factory,
284291
)
285292

286293

tests/test_cli.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def test_dev() -> None:
2929
"workers": None,
3030
"root_path": "",
3131
"proxy_headers": True,
32+
"factory": False,
3233
}
3334
assert "Using import string single_file_app:app" in result.output
3435
assert (
@@ -71,6 +72,7 @@ def test_dev_args() -> None:
7172
"workers": None,
7273
"root_path": "/api",
7374
"proxy_headers": False,
75+
"factory": False,
7476
}
7577
assert "Using import string single_file_app:api" in result.output
7678
assert (
@@ -97,6 +99,7 @@ def test_run() -> None:
9799
"workers": None,
98100
"root_path": "",
99101
"proxy_headers": True,
102+
"factory": False,
100103
}
101104
assert "Using import string single_file_app:app" in result.output
102105
assert (
@@ -141,6 +144,7 @@ def test_run_args() -> None:
141144
"workers": 2,
142145
"root_path": "/api",
143146
"proxy_headers": False,
147+
"factory": False,
144148
}
145149
assert "Using import string single_file_app:api" in result.output
146150
assert (

tests/test_utils_package.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,8 @@ def test_package_dir_no_app() -> None:
432432
with pytest.raises(FastAPICLIException) as e:
433433
get_import_string(path=Path("package/core/utils.py"))
434434
assert (
435-
"Could not find FastAPI app in module, try using --app" in e.value.args[0]
435+
"Could not find FastAPI app or app factory in module, try using --app"
436+
in e.value.args[0]
436437
)
437438

438439

0 commit comments

Comments
 (0)