Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/hypercorn/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def main(sys_args: list[str] | None = None) -> int:
parser.add_argument(
"--statsd-host", help="The host:port of the statsd server", default=sentinel
)
parser.add_argument("--statsd-prefix", help="Prefix for all statsd messages", default="")
parser.add_argument("--statsd-prefix", help="Prefix for all statsd messages", default=sentinel)
parser.add_argument(
"-m",
"--umask",
Expand Down
25 changes: 25 additions & 0 deletions tests/test___main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,28 @@ def test_verify_mode_conversion(monkeypatch: MonkeyPatch) -> None:

hypercorn.__main__.main(["--verify-mode", "CERT_REQUIRED", "asgi:App"])
run_multiple.assert_called()


def test_statsd_prefix_preserves_config_file(tmp_path, monkeypatch: MonkeyPatch) -> None:
"""CLI default must not wipe statsd_prefix loaded from a config file (#382)."""
run_multiple = Mock()
monkeypatch.setattr(hypercorn.__main__, "run", run_multiple)
cfg = tmp_path / "statsd_config.py"
cfg.write_text('statsd_prefix = "myapp."\n')
hypercorn.__main__.main(["--config", f"file:{cfg}", "asgi:App"])
run_multiple.assert_called()
config = run_multiple.call_args_list[0][0][0]
assert config.statsd_prefix == "myapp."


def test_statsd_prefix_cli_overrides_config(tmp_path, monkeypatch: MonkeyPatch) -> None:
run_multiple = Mock()
monkeypatch.setattr(hypercorn.__main__, "run", run_multiple)
cfg = tmp_path / "statsd_config.py"
cfg.write_text('statsd_prefix = "myapp."\n')
hypercorn.__main__.main(
["--config", f"file:{cfg}", "--statsd-prefix", "cli.", "asgi:App"]
)
run_multiple.assert_called()
config = run_multiple.call_args_list[0][0][0]
assert config.statsd_prefix == "cli."