Skip to content

Commit 0830161

Browse files
committed
Improve coverage
1 parent 260242e commit 0830161

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from fastapi import FastAPI
2+
3+
app = FastAPI()
4+
5+
6+
@app.get("/")
7+
def app_root():
8+
return {"message": "badly configured app"}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[tool.fastapi.cli.run]
2+
port = "http"

tests/test_cli.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,16 @@ def test_run_error() -> None:
210210
assert "Path does not exist non_existing_file.py" in result.output
211211

212212

213+
def test_project_config_error() -> None:
214+
with changing_dir(assets_path / "projects/bad_configured_app"):
215+
result = runner.invoke(app, ["run"])
216+
assert result.exit_code == 2, result.output
217+
assert (
218+
"Error parsing pyproject.toml: key 'tool.fastapi.cli.run.port'"
219+
in result.output
220+
)
221+
222+
213223
def test_dev_help() -> None:
214224
result = runner.invoke(app, ["dev", "--help"])
215225
assert result.exit_code == 0, result.output

tests/utils.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ def changing_dir(directory: Union[str, Path]) -> Generator[None, None, None]:
1919

2020

2121
@contextmanager
22-
def importing(names: Union[str, list[str]]) -> Generator[None, None, None]:
22+
def importing(names: list[str]) -> Generator[None, None, None]:
2323
for name in names:
24-
if name in sys.modules:
24+
if name in sys.modules: # pragma: no cover
2525
warnings.warn(
2626
f"{name} is already imported",
2727
category=UserWarning,
@@ -30,8 +30,6 @@ def importing(names: Union[str, list[str]]) -> Generator[None, None, None]:
3030
try:
3131
yield
3232
finally:
33-
if isinstance(names, str):
34-
names = [names]
3533
for name in names:
3634
if name in sys.modules:
3735
del sys.modules[name]

0 commit comments

Comments
 (0)