@@ -133,8 +133,8 @@ def test_dev_args() -> None:
133133 }
134134 assert "Using import string: single_file_app:api" in result .output
135135 assert "Starting development server 🚀" in result .output
136- assert "Server started at http://192.168.0.2:8080" in result .output
137- assert "Documentation at http://192.168.0.2:8080/docs" in result .output
136+ assert "Server started at http://192.168.0.2:8080/api " in result .output
137+ assert "Documentation at http://192.168.0.2:8080/api/ docs" in result .output
138138 assert (
139139 "Running in development mode, for production use: fastapi run"
140140 in result .output
@@ -323,8 +323,8 @@ def test_run_args() -> None:
323323
324324 assert "Using import string: single_file_app:api" in result .output
325325 assert "Starting production server 🚀" in result .output
326- assert "Server started at http://192.168.0.2:8080" in result .output
327- assert "Documentation at http://192.168.0.2:8080/docs" in result .output
326+ assert "Server started at http://192.168.0.2:8080/api " in result .output
327+ assert "Documentation at http://192.168.0.2:8080/api/ docs" in result .output
328328 assert (
329329 "Running in development mode, for production use: fastapi run"
330330 not in result .output
@@ -475,6 +475,58 @@ def test_docs_urls_custom_redoc() -> None:
475475 assert "http://127.0.0.1:8000/custom-redoc-url" in result .output
476476
477477
478+ @pytest .mark .parametrize (
479+ ("app_name" , "expected_url" ),
480+ [
481+ ("only_docs" , "http://127.0.0.1:8000/api/docs" ),
482+ ("only_redoc" , "http://127.0.0.1:8000/api/redoc" ),
483+ ],
484+ )
485+ def test_docs_urls_root_path_option (app_name : str , expected_url : str ) -> None :
486+ with changing_dir (assets_path ):
487+ with patch .object (uvicorn , "run" ) as mock_run :
488+ result = runner .invoke (
489+ app ,
490+ [
491+ "dev" ,
492+ "single_file_docs.py" ,
493+ "--app" ,
494+ app_name ,
495+ "--root-path" ,
496+ "/api" ,
497+ ],
498+ )
499+ assert result .exit_code == 0 , result .output
500+ assert mock_run .called
501+
502+ assert expected_url in result .output
503+
504+
505+ @pytest .mark .parametrize (
506+ ("app_name" , "expected_url" ),
507+ [
508+ ("docs_root_path" , "http://127.0.0.1:8000/api/docs" ),
509+ ("redoc_root_path" , "http://127.0.0.1:8000/api/redoc" ),
510+ ],
511+ )
512+ def test_docs_urls_root_path_param (app_name : str , expected_url : str ) -> None :
513+ with changing_dir (assets_path ):
514+ with patch .object (uvicorn , "run" ) as mock_run :
515+ result = runner .invoke (
516+ app ,
517+ [
518+ "dev" ,
519+ "single_file_docs.py" ,
520+ "--app" ,
521+ app_name ,
522+ ],
523+ )
524+ assert result .exit_code == 0 , result .output
525+ assert mock_run .called
526+
527+ assert expected_url in result .output
528+
529+
478530def test_run_error () -> None :
479531 with changing_dir (assets_path ):
480532 result = runner .invoke (app , ["run" , "non_existing_file.py" ])
0 commit comments