Skip to content

Commit c312fd2

Browse files
authored
test: patch params_storage on the class so the teardown test survives faststream 0.7.7's __slots__ (#256)
1 parent 2f0c9f4 commit c312fd2

1 file changed

Lines changed: 7 additions & 15 deletions

File tree

‎tests/test_faststream_bootstrap.py‎

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -302,26 +302,18 @@ async def test_faststream_prometheus_is_skipped_without_middleware_or_registry(b
302302
bootstrapper.teardown()
303303

304304

305-
def test_faststream_logging_teardown_runs_super_when_broker_write_raises(broker: RedisBroker) -> None:
305+
def test_faststream_logging_teardown_runs_super_when_broker_write_raises(
306+
broker: RedisBroker, monkeypatch: pytest.MonkeyPatch
307+
) -> None:
306308
bootstrap_config = build_faststream_config(broker=broker)
307309
instrument = FastStreamLoggingInstrument(bootstrap_config=bootstrap_config)
308310
instrument.bootstrap()
309311

310-
# Make broker.config.logger.params_storage raise on write by promoting the instance to a
311-
# subclass that shadows params_storage with a property whose setter always raises.
312-
logger_state = broker.config.logger
313-
314-
class _BrokenLoggerState(type(logger_state)): # ty: ignore[unsupported-base]
315-
@property # type: ignore[override]
316-
def params_storage(self) -> object: # pragma: no cover
317-
return None
318-
319-
@params_storage.setter
320-
def params_storage(self, _value: object) -> None:
321-
msg = "broker write boom"
322-
raise RuntimeError(msg)
312+
def _raise_on_write(_self: object, _value: object) -> None:
313+
msg = "broker write boom"
314+
raise RuntimeError(msg)
323315

324-
logger_state.__class__ = _BrokenLoggerState
316+
monkeypatch.setattr(type(broker.config.logger), "params_storage", property(fset=_raise_on_write), raising=False)
325317

326318
# super().teardown() still runs (LoggingInstrument's structlog reset); broker write raises last.
327319
with pytest.raises(RuntimeError, match="broker write boom"):

0 commit comments

Comments
 (0)