From 9e75f288c24caf7462f4d9938dcbf92b97ecc01e Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Mon, 20 Jul 2026 13:08:43 +0000 Subject: [PATCH] tests: give mock homeservers a real string hostname MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Rust `LoggingContext` requires `server_name` to be a `str`. Three test suites built a mock homeserver whose `hostname` was left as an auto-generated `Mock`, which flowed into `server_name` (via `DatabasePool`, `StateHandler` and `ApplicationServicesHandler`) and raised `TypeError: argument 'server_name': 'Mock' object is not an instance of 'str'` once a `LoggingContext`/`Measure` was constructed — 42 trial errors in CI. Set `hostname` to the server name each suite already uses, so the mocks match what production passes. Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01VF56cZ93AqpuGCf8yguCcR --- tests/handlers/test_appservice.py | 1 + tests/storage/test_base.py | 2 +- tests/test_state.py | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/handlers/test_appservice.py b/tests/handlers/test_appservice.py index 08a4ab624a..a649f512e6 100644 --- a/tests/handlers/test_appservice.py +++ b/tests/handlers/test_appservice.py @@ -77,6 +77,7 @@ class AppServiceHandlerTestCase(unittest.TestCase): self.reactor, self.clock = get_clock() hs = Mock() + hs.hostname = "test_server" def test_run_as_background_process( desc: "LiteralString", diff --git a/tests/storage/test_base.py b/tests/storage/test_base.py index 577229c119..e67d36cf63 100644 --- a/tests/storage/test_base.py +++ b/tests/storage/test_base.py @@ -105,7 +105,7 @@ class SQLBaseStoreTestCase(unittest.TestCase): # To fix isinstance(...) checks. fake_engine.__class__ = engine.__class__ # type: ignore[assignment] - db = DatabasePool(Mock(), Mock(config=db_config), fake_engine) + db = DatabasePool(Mock(hostname="test"), Mock(config=db_config), fake_engine) db._db_pool = conn_pool self.datastore = SQLBaseStore(db, None, hs) # type: ignore[arg-type] diff --git a/tests/test_state.py b/tests/test_state.py index b69a09dab5..d2e50cf94b 100644 --- a/tests/test_state.py +++ b/tests/test_state.py @@ -245,6 +245,7 @@ class StateTestCase(unittest.TestCase): ) reactor, clock = get_clock() hs.config = default_config(server_name="tesths", parse=True) + hs.hostname = "tesths" hs.get_datastores.return_value = Mock( main=self.dummy_store, state_deletion=dummy_deletion_store,