33from pathlib import Path
44from unittest .mock import patch
55
6+ import pytest
67import uvicorn
78from typer .testing import CliRunner
89
@@ -391,11 +392,18 @@ def test_run_env_vars_and_args() -> None:
391392 assert "Documentation at http://0.0.0.0:8080/docs" in result .output
392393
393394
394- def test_no_openapi () -> None :
395+ @pytest .mark .parametrize (
396+ "app_name" ,
397+ [
398+ "openapi_none" ,
399+ "docs_none_redoc_none" ,
400+ ],
401+ )
402+ def test_docs_urls_disabled (app_name : str ) -> None :
395403 with changing_dir (assets_path ):
396404 with patch .object (uvicorn , "run" ) as mock_run :
397405 result = runner .invoke (
398- app , ["dev" , "single_file_docs.py" , "--app" , "no_openapi" ]
406+ app , ["dev" , "single_file_docs.py" , "--app" , app_name ]
399407 )
400408 assert result .exit_code == 0 , result .output
401409 assert mock_run .called
@@ -404,24 +412,24 @@ def test_no_openapi() -> None:
404412 assert "http://127.0.0.1:8000/redoc" not in result .output
405413
406414
407- def test_none_docs () -> None :
415+ def test_docs_urls_only_docs () -> None :
408416 with changing_dir (assets_path ):
409417 with patch .object (uvicorn , "run" ) as mock_run :
410418 result = runner .invoke (
411- app , ["dev" , "single_file_docs.py" , "--app" , "none_docs " ]
419+ app , ["dev" , "single_file_docs.py" , "--app" , "only_docs " ]
412420 )
413421 assert result .exit_code == 0 , result .output
414422 assert mock_run .called
415423
416- assert "http://127.0.0.1:8000/docs" not in result .output
424+ assert "http://127.0.0.1:8000/docs" in result .output
417425 assert "http://127.0.0.1:8000/redoc" not in result .output
418426
419427
420- def test_no_docs () -> None :
428+ def test_docs_urls_only_redoc () -> None :
421429 with changing_dir (assets_path ):
422430 with patch .object (uvicorn , "run" ) as mock_run :
423431 result = runner .invoke (
424- app , ["dev" , "single_file_docs.py" , "--app" , "no_docs " ]
432+ app , ["dev" , "single_file_docs.py" , "--app" , "only_redoc " ]
425433 )
426434 assert result .exit_code == 0 , result .output
427435 assert mock_run .called
@@ -430,20 +438,7 @@ def test_no_docs() -> None:
430438 assert "http://127.0.0.1:8000/docs" not in result .output
431439
432440
433- def test_no_redoc () -> None :
434- with changing_dir (assets_path ):
435- with patch .object (uvicorn , "run" ) as mock_run :
436- result = runner .invoke (
437- app , ["dev" , "single_file_docs.py" , "--app" , "no_redoc" ]
438- )
439- assert result .exit_code == 0 , result .output
440- assert mock_run .called
441-
442- assert "http://127.0.0.1:8000/docs" in result .output
443- assert "http://127.0.0.1:8000/redocs" not in result .output
444-
445-
446- def test_full_docs () -> None :
441+ def test_docs_urls_full_docs () -> None :
447442 with changing_dir (assets_path ):
448443 with patch .object (uvicorn , "run" ) as mock_run :
449444 result = runner .invoke (
@@ -456,7 +451,7 @@ def test_full_docs() -> None:
456451 assert "http://127.0.0.1:8000/redoc" not in result .output # docs has precedence
457452
458453
459- def test_custom_docs () -> None :
454+ def test_docs_urls_custom_docs () -> None :
460455 with changing_dir (assets_path ):
461456 with patch .object (uvicorn , "run" ) as mock_run :
462457 result = runner .invoke (
@@ -468,7 +463,7 @@ def test_custom_docs() -> None:
468463 assert "http://127.0.0.1:8000/custom-docs-url" in result .output
469464
470465
471- def test_custom_redoc () -> None :
466+ def test_docs_urls_custom_redoc () -> None :
472467 with changing_dir (assets_path ):
473468 with patch .object (uvicorn , "run" ) as mock_run :
474469 result = runner .invoke (
0 commit comments