diff --git a/features/steps/tdd_engine_cache_toctou_steps.py b/features/steps/tdd_engine_cache_toctou_steps.py index 5ee1c8e7a..5b0859027 100644 --- a/features/steps/tdd_engine_cache_toctou_steps.py +++ b/features/steps/tdd_engine_cache_toctou_steps.py @@ -26,9 +26,9 @@ def _get_engine_cache_module() -> Any: return m -def _get_memory_engines() -> dict[str, Any]: +def _get_memory_engines() -> Any: """Return the live MEMORY_ENGINES cache dictionary.""" - return _get_engine_cache_module().MEMORY_ENGINES # type: ignore[no-any-return] + return _get_engine_cache_module().MEMORY_ENGINES def _get_memory_engines_lock() -> Any: @@ -57,11 +57,11 @@ def _clear_memory_engines() -> None: def _restore_locks(ctx: Context) -> None: """Restore original lock references if the tracking proxy was installed.""" if hasattr(ctx, "_engine_cache_module") and hasattr(ctx, "_original_lock"): - ctx._engine_cache_module.MEMORY_ENGINES_LOCK = ctx._original_lock # type: ignore[assignment] + setattr(ctx._engine_cache_module, "MEMORY_ENGINES_LOCK", ctx._original_lock) if hasattr(ctx._engine_cache_module, "_original_lock_backup"): del ctx._engine_cache_module._original_lock_backup if hasattr(ctx, "_uow_module") and hasattr(ctx, "_original_uow_lock"): - ctx._uow_module.MEMORY_ENGINES_LOCK = ctx._original_uow_lock # type: ignore[assignment] + setattr(ctx._uow_module, "MEMORY_ENGINES_LOCK", ctx._original_uow_lock) # --------------------------------------------------------------------------- @@ -117,13 +117,13 @@ def step_track_lock_acquisition(ctx: Context) -> None: counting_lock = _CountingLock() ctx._engine_cache_module = engine_cache_module ctx._original_lock = real_lock - engine_cache_module.MEMORY_ENGINES_LOCK = counting_lock # type: ignore[assignment] + setattr(engine_cache_module, "MEMORY_ENGINES_LOCK", counting_lock) import cleveragents.infrastructure.database.unit_of_work as _uow_module ctx._uow_module = _uow_module ctx._original_uow_lock = _uow_module.MEMORY_ENGINES_LOCK - _uow_module.MEMORY_ENGINES_LOCK = counting_lock # type: ignore[assignment] + setattr(_uow_module, "MEMORY_ENGINES_LOCK", counting_lock) # --------------------------------------------------------------------------- @@ -146,9 +146,7 @@ def step_access_uow_engine(ctx: Context, url: str) -> None: _restore_locks(ctx) -@when( - '{count:d} threads each access the engine cache for "{url}"' -) +@when('{count:d} threads each access the engine cache for "{url}"') def step_concurrent_cache_access(ctx: Context, count: int, url: str) -> None: """Directly test the engine cache's lock by calling create_engine in threads. @@ -188,9 +186,9 @@ def step_concurrent_cache_access(ctx: Context, count: int, url: str) -> None: t.join() if errors: - raise AssertionError( - f"Worker threads raised exceptions: {errors}" - ) from errors[0] + raise AssertionError(f"Worker threads raised exceptions: {errors}") from errors[ + 0 + ] ctx.concurrent_engines = engines @@ -202,9 +200,9 @@ def step_concurrent_cache_access(ctx: Context, count: int, url: str) -> None: @then("MEMORY_ENGINES_LOCK should be accessible from the engine_cache module") def step_lock_accessible(ctx: Context) -> None: - assert hasattr( - ctx.engine_cache_module, "MEMORY_ENGINES_LOCK" - ), "MEMORY_ENGINES_LOCK not found in engine_cache module" + assert hasattr(ctx.engine_cache_module, "MEMORY_ENGINES_LOCK"), ( + "MEMORY_ENGINES_LOCK not found in engine_cache module" + ) @then("MEMORY_ENGINES_LOCK should be a threading.Lock instance")