fix (fastapi): skip init=False fields when copying Dependant - #2966
Merged
Conversation
Dataclass fields declared with `field(init=False)` cannot be passed to the constructor, so building `_FastStreamDependant` from a parent `Dependant` that has any such field raised a TypeError. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Move tests/brokers/redis/test_cluster*.py into tests/brokers/redis/cluster/ and test_sentinel.py into tests/brokers/redis/sentinel/. Also bump the project version to 0.7.3 in uv.lock. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Importing from a conftest.py is unsafe: pytest loads conftest modules specially, so a direct import can yield a duplicated/mismatched module. Declare the Settings dataclasses in plain settings.py helpers next to each broker's tests and import them from both the conftest and the test files. Also move SettingsCluster and the settings_cluster fixture down into tests/brokers/redis/cluster/, where they are the only users. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The kafka and confluent test_batch_body.py modules were identical modulo naming: 500 lines whose only real differences were the import aliases and `m.key` vs `m.key()`. Worse, the confluent module imported `faststream.kafka.response` for its non-async tests, so confluent's own `batch_bodies` setter had no unit coverage at all. Move the shared cases into a `BatchKeysTestcase` in tests/brokers/base, driven by a single `KEY_ALIGNMENT_CASES` table, and leave each broker a thin subclass supplying its own classes and key accessor. Keep only the e2e test: `key_for()` is reached through the TestBroker batch publish path, so the middleware test covers the setter, _align_keys and key_for as a superset of what the unit test checked. Also drop `test_random_bodies` -- same inputs as `test_keys_order` with a membership assertion too weak to catch a mis-association -- folding its unique cases in as exact-equality params, and drop the redis `test_stream_same_group_executes_message_exactly_once` duplicate after strengthening the remaining test to assert the payload. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
borisalekseev
approved these changes
Jul 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Three related changes on this branch.
fix (fastapi)— skipinit=Falsefields when copying FastAPI'sDependant. Newer FastAPI versions mark someDependantfieldsinit=False, so passing them to the constructor raises.chore(tests)— group the Redis cluster and sentinel tests intotests/brokers/redis/cluster/andtests/brokers/redis/sentinel/subpackages.chore(tests)— stop importing fromconftest.pymodules. pytest loads conftest modules specially, so a direct import (from .conftest import Settings) can yield a duplicated/mismatched module and confusing collection errors. Each broker'sSettingsdataclass now lives in a plainsettings.pyhelper imported by both the conftest and the test files.SettingsClusterand thesettings_clusterfixture moved down intotests/brokers/redis/cluster/, their only users. The rule is documented in thetesting-patternsskill.Type of change
Checklist
just lintshows no errors)just static-analysisjust test-coverage—tests/brokers/redispasses (624 passed, 2 skipped, 1 xfailed) and the connected suites collect cleanly, but the full coverage run was not executed locally