Skip to content

feat: added scoped mock for improved concurrent test exection#54

Merged
petruki merged 1 commit intomasterfrom
staging
May 2, 2026
Merged

feat: added scoped mock for improved concurrent test exection#54
petruki merged 1 commit intomasterfrom
staging

Conversation

@petruki
Copy link
Copy Markdown
Member

@petruki petruki commented May 2, 2026

This pull request introduces significant improvements to the mocking capabilities of the Switcher Client SDK for Python, focusing on making forced feature flag values (mocks) isolated to each execution context. This enhances test reliability, especially for concurrent or parallel test runs. The changes also update documentation and add new tests to verify the improved isolation.

Improvements to mocking and test isolation:

  • Refactored the Bypasser class in bypasser.py to use Python's ContextVar, ensuring that forced values (mocks) are scoped to the current execution context. This prevents mock leakage between concurrent tests and allows for safe, parallel test execution. Added a new clear() method to reset forced values per context.
  • Updated the SDK documentation in README.md to clarify that built-in mocking now provides scoped mock isolation for concurrent execution, and added details about the new context-scoped behavior. [1] [2]
  • Added new tests in test_switcher_stub.py to verify that mocked feature flag values are properly isolated and can be overridden in different execution contexts using Context. [1] [2]

Resource cleanup and robustness:

  • Ensured that Bypasser.clear() is called during client context building and resource cleanup in client.py, so that forced values do not persist across tests or client lifecycles. [1] [2]

Minor codebase cleanup:

  • Removed an unused key property from the Key class in key.py for simplicity.

@petruki petruki added this to the v1.1.0 milestone May 2, 2026
@petruki petruki self-assigned this May 2, 2026
@petruki petruki added the enhancement New feature or request label May 2, 2026
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 2, 2026

@petruki petruki merged commit 5795bd9 into master May 2, 2026
15 checks passed
@petruki petruki deleted the staging branch May 2, 2026 06:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant