From 641e8c53bf741fde724818f963ec035a63eda2f7 Mon Sep 17 00:00:00 2001 From: Irfanuddin Shafi Ahmed Date: Sat, 29 Oct 2022 13:14:22 +0530 Subject: [PATCH] Add test scenario for `--uds` flag when file exists (#1741) Co-authored-by: Marcelo Trylesinski --- setup.cfg | 2 +- tests/test_cli.py | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/setup.cfg b/setup.cfg index 33c3e95a3..8ec8fbbf6 100644 --- a/setup.cfg +++ b/setup.cfg @@ -82,7 +82,7 @@ plugins = [coverage:report] precision = 2 -fail_under = 97.69 +fail_under = 97.79 show_missing = true skip_covered = true exclude_lines = diff --git a/tests/test_cli.py b/tests/test_cli.py index 0d34d1d36..ae22fef6a 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -91,10 +91,20 @@ def test_cli_call_multiprocess_run() -> None: mock_run.assert_called_once() +@pytest.fixture(params=(True, False)) +def uds_file( + tmp_path: Path, request: pytest.FixtureRequest +) -> Path: # pragma: py-win32 + file = tmp_path / "uvicorn.sock" + should_create_file = request.param + if should_create_file: + file.touch(exist_ok=True) + return file + + @pytest.mark.skipif(sys.platform == "win32", reason="require unix-like system") -def test_cli_uds(tmp_path: Path) -> None: # pragma: py-win32 +def test_cli_uds(uds_file: Path) -> None: # pragma: py-win32 runner = CliRunner() - uds_file = tmp_path / "uvicorn.sock" with mock.patch.object(Config, "bind_socket") as mock_bind_socket: with mock.patch.object(Multiprocess, "run") as mock_run: