test(flags): make wrong-key load_feature_flags deterministic#432
Merged
test(flags): make wrong-key load_feature_flags deterministic#432
Conversation
Contributor
posthog-python Compliance ReportDate: 2026-02-13 13:43:18 UTC ✅ All Tests Passed!29/29 tests passed Capture Tests✅ 29/29 tests passed View Details
|
This reverts commit 899360e.
Contributor
Author
|
@greptile-apps please review |
andrewm4894
approved these changes
Feb 13, 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.
Summary
Stabilize feature-flag tests in CI and remove runtime-dependent behavior in capture cache handling.
Example failure run where 3.10 and 11 passes, but 13 and 14 fails https://github.com/PostHog/posthog-python/actions/runs/21986040963/job/63520352185?pr=431
Changes
test_load_feature_flags_wrong_keydeterministic by mockingposthog.client.getto raiseAPIError(401, "Unauthorized")and mockingposthog.client.Poller.test_capture_multiple_users_doesnt_out_of_memorydeterministic by settingclient.distinct_ids_feature_flags_reported.max_size = 100directly on the instance (with an explanatory comment).Client._capture_feature_flag_calledto avoid implicitdefaultdictmissing-key insertion and use explicit get/assign before adding reported flag keys.Why
CI reproduced a non-deterministic failure in capture-cache size assertions (
101 != 1) that did not consistently reproduce locally. These changes remove reliance on runtime-specific insertion behavior and network-dependent test setup.Validation
pytest -q posthog/test/test_feature_flags.py -k "test_load_feature_flags_wrong_key"pytest -q posthog/test/test_feature_flags.py -k "test_capture_multiple_users_doesnt_out_of_memory"pytest -q posthog/test/test_feature_flags.py -k "TestCaptureCalls"