From ef8e75db78fc5aa5d33239bd7eda82f89b41c177 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Tue, 4 Nov 2025 17:36:31 -0800 Subject: [PATCH] Backported CliRunner fix from e3eb356a Removed obsolete mix_stderr=False arguments from CliRunner() calls which are not supported in Click 8.3.0. --- tests/test_cli.py | 15 +++++++++------ tests/test_config_dir.py | 2 +- tests/test_crossdb.py | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 9ca50cbe..35d8419f 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -193,7 +193,7 @@ def test_version(): @pytest.mark.parametrize("invalid_port", ["-1", "0.5", "dog", "65536"]) def test_serve_invalid_ports(invalid_port): - runner = CliRunner(mix_stderr=False) + runner = CliRunner() result = runner.invoke(cli, ["--port", invalid_port]) assert result.exit_code == 2 assert "Invalid value for '-p'" in result.stderr @@ -209,7 +209,7 @@ def test_setting(): def test_setting_type_validation(): - runner = CliRunner(mix_stderr=False) + runner = CliRunner() result = runner.invoke(cli, ["--setting", "default_page_size", "dog"]) assert result.exit_code == 2 assert '"default_page_size" should be an integer' in result.stderr @@ -239,17 +239,20 @@ def test_setting_default_allow_sql(default_allow_sql): def test_config_deprecated(): # The --config option should show a deprecation message - runner = CliRunner(mix_stderr=False) + runner = CliRunner() result = runner.invoke( cli, ["--config", "allow_download:off", "--get", "/-/settings.json"] ) assert result.exit_code == 0 - assert not json.loads(result.output)["allow_download"] - assert "will be deprecated in" in result.stderr + # Extract JSON from output (skip the deprecation warning line) + output_lines = result.output.strip().split("\n") + json_output = "\n".join(line for line in output_lines if line.startswith("{")) + assert not json.loads(json_output)["allow_download"] + assert "will be deprecated in" in result.output def test_sql_errors_logged_to_stderr(): - runner = CliRunner(mix_stderr=False) + runner = CliRunner() result = runner.invoke(cli, ["--get", "/_memory.json?sql=select+blah"]) assert result.exit_code == 1 assert "sql = 'select blah', params = {}: no such column: blah\n" in result.stderr diff --git a/tests/test_config_dir.py b/tests/test_config_dir.py index c2af3836..528b13d4 100644 --- a/tests/test_config_dir.py +++ b/tests/test_config_dir.py @@ -114,7 +114,7 @@ def test_settings(config_dir_client): def test_error_on_config_json(tmp_path_factory): config_dir = tmp_path_factory.mktemp("config-dir") (config_dir / "config.json").write_text(json.dumps(SETTINGS), "utf-8") - runner = CliRunner(mix_stderr=False) + runner = CliRunner() result = runner.invoke(cli, [str(config_dir), "--get", "/-/settings.json"]) assert result.exit_code == 1 assert "config.json should be renamed to settings.json" in result.stderr diff --git a/tests/test_crossdb.py b/tests/test_crossdb.py index 01c51130..be2e0705 100644 --- a/tests/test_crossdb.py +++ b/tests/test_crossdb.py @@ -44,7 +44,7 @@ def test_crossdb_warning_if_too_many_databases(tmp_path_factory): conn = sqlite3.connect(path) conn.execute("vacuum") dbs.append(path) - runner = CliRunner(mix_stderr=False) + runner = CliRunner() result = runner.invoke( cli, [