@@ -152,6 +152,84 @@ def test_run_args() -> None:
152152 assert "│ fastapi dev" in result .output
153153
154154
155+ def test_no_openapi () -> None :
156+ with changing_dir (assets_path ):
157+ with patch .object (uvicorn , "run" ) as mock_run :
158+ result = runner .invoke (
159+ app , ["dev" , "single_file_docs.py" , "--app-name" , "no_openapi" ]
160+ )
161+ assert result .exit_code == 0 , result .output
162+ assert mock_run .called
163+
164+ assert "│ API docs: http://127.0.0.1:8000/docs" not in result .output
165+ assert "│ http://127.0.0.1:8000/redoc" not in result .output
166+
167+
168+ def test_none_docs () -> None :
169+ with changing_dir (assets_path ):
170+ with patch .object (uvicorn , "run" ) as mock_run :
171+ result = runner .invoke (
172+ app , ["dev" , "single_file_docs.py" , "--app-name" , "none_docs" ]
173+ )
174+ assert result .exit_code == 0 , result .output
175+ assert mock_run .called
176+
177+ assert "│ API docs: http://127.0.0.1:8000/docs" not in result .output
178+ assert "│ http://127.0.0.1:8000/redoc" not in result .output
179+
180+
181+ def test_no_docs () -> None :
182+ with changing_dir (assets_path ):
183+ with patch .object (uvicorn , "run" ) as mock_run :
184+ result = runner .invoke (
185+ app , ["dev" , "single_file_docs.py" , "--app-name" , "no_docs" ]
186+ )
187+ assert result .exit_code == 0 , result .output
188+ assert mock_run .called
189+
190+ assert "│ API docs: http://127.0.0.1:8000/redoc" in result .output
191+ assert "│ http://127.0.0.1:8000/docs" not in result .output
192+
193+
194+ def test_no_redoc () -> None :
195+ with changing_dir (assets_path ):
196+ with patch .object (uvicorn , "run" ) as mock_run :
197+ result = runner .invoke (
198+ app , ["dev" , "single_file_docs.py" , "--app-name" , "no_redoc" ]
199+ )
200+ assert result .exit_code == 0 , result .output
201+ assert mock_run .called
202+
203+ assert "│ API docs: http://127.0.0.1:8000/docs" in result .output
204+ assert "│ http://127.0.0.1:8000/docs" not in result .output
205+
206+
207+ def test_full_docs () -> None :
208+ with changing_dir (assets_path ):
209+ with patch .object (uvicorn , "run" ) as mock_run :
210+ result = runner .invoke (
211+ app , ["dev" , "single_file_docs.py" , "--app-name" , "full_docs" ]
212+ )
213+ assert result .exit_code == 0 , result .output
214+ assert mock_run .called
215+
216+ assert "│ API docs: http://127.0.0.1:8000/docs" in result .output
217+ assert "│ http://127.0.0.1:8000/redoc" in result .output
218+
219+
220+ def test_custom_docs () -> None :
221+ with changing_dir (assets_path ):
222+ with patch .object (uvicorn , "run" ) as mock_run :
223+ result = runner .invoke (
224+ app , ["dev" , "single_file_docs.py" , "--app-name" , "custom_docs" ]
225+ )
226+ assert result .exit_code == 0 , result .output
227+ assert mock_run .called
228+
229+ assert "│ API docs: http://127.0.0.1:8000/custom-docs-url" in result .output
230+ assert "│ http://127.0.0.1:8000/custom-redoc-url" in result .output
231+
232+
155233def test_run_error () -> None :
156234 with changing_dir (assets_path ):
157235 result = runner .invoke (app , ["run" , "non_existing_file.py" ])
0 commit comments