Skip to content

feat: added testing decorator for switcher mocks#55

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

feat: added testing decorator for switcher mocks#55
petruki merged 1 commit intomasterfrom
staging

Conversation

@petruki
Copy link
Copy Markdown
Member

@petruki petruki commented May 2, 2026

This pull request introduces a new decorator-based testing API for feature flag mocking in the Switcher Client SDK for Python, along with updates to documentation and comprehensive tests. The main goal is to simplify and improve the safety of mocking feature flags in test scenarios, making it easier to isolate and clean up mocks automatically after each test, including support for both synchronous and asynchronous test functions.

Key changes:

Decorator-Based Test Mocking API:

  • Added a new switcher_client/testing.py module with the assume_test builder and switcher_test decorator, enabling test-scoped, fluent, and safe mocking of feature flags with automatic cleanup, even on errors or in async tests. This ensures mocks do not leak between tests and supports advanced mocking rules and metadata.
  • Exported assume_test and switcher_test from the SDK’s main module (switcher_client/__init__.py) for easy import by users. [1] [2]

Documentation Updates:

  • Updated the README.md to describe the new decorator-based mocking approach, including usage examples, behavior, and limitations, and clarified the mocking feature description. [1] [2] [3] [4]

Testing and Validation:

  • Added a new test file tests/test_switcher_stub_decorator.py with comprehensive unit tests covering all aspects of the new decorator API, including error handling, cleanup, support for metadata, multiple mocks, context isolation, and async test support.

Minor Improvements:

  • Fixed import order to allow LoadSnapshotOptions to be imported from the main SDK entrypoint.

These changes collectively make feature flag mocking for testing more robust, convenient, and less error-prone for SDK users.

@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 f87f0a8 into master May 2, 2026
15 checks passed
@petruki petruki deleted the staging branch May 2, 2026 22:02
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