Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(tests): sort scope sets so test ids stay stable (#94457)

Raúl Negrón-Otero7c00af2b3ea5
diff --git a/posthog/test/test_scopes.py b/posthog/test/test_scopes.py
index 837d88cd8753..e0cf538d2c44 100644
--- a/posthog/test/test_scopes.py
+++ b/posthog/test/test_scopes.py
@@ -76,11 +76,18 @@ class TestDowngradeScopesToReadOnly(BaseTest):
self.assertIn("openid", result)
+# sorted: parameterized bakes the iteration order into the test ids, and a frozenset
+# iterates in hash order, which differs per process.
+INTERNAL_SCOPE_CASES = [
+ (f"{obj}:{action}",) for obj in sorted(INTERNAL_API_SCOPE_OBJECTS) for action in API_SCOPE_ACTIONS
+]
+
+
class TestScopeSets(BaseTest):
def test_all_scopes_matches_scope_descriptions_keys(self) -> None:
self.assertEqual(ALL_SCOPES, frozenset(get_scope_descriptions().keys()))
- @parameterized.expand([(f"{obj}:{action}",) for obj in INTERNAL_API_SCOPE_OBJECTS for action in API_SCOPE_ACTIONS])
+ @parameterized.expand(INTERNAL_SCOPE_CASES)
def test_all_scopes_excludes_internal_scope(self, scope: str) -> None:
self.assertNotIn(scope, ALL_SCOPES)
@@ -98,7 +105,7 @@ class TestScopeSets(BaseTest):
# they are not part of the UNPRIVILEGED broad-default set.
self.assertNotIn(oidc, UNPRIVILEGED_SCOPES)
- @parameterized.expand([(f"{obj}:{action}",) for obj in INTERNAL_API_SCOPE_OBJECTS for action in API_SCOPE_ACTIONS])
+ @parameterized.expand(INTERNAL_SCOPE_CASES)
def test_unprivileged_scopes_excludes_internal_scope(self, scope: str) -> None:
self.assertNotIn(scope, UNPRIVILEGED_SCOPES)