Implement a pytest plugin to help with testing

Open
#135 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
testing

Research direction

Start by reading the pytest-plugin discussion in PR #5108 and the requested fixture and context-manager examples in this issue. Done means a reusable pytest fixture or context manager overrides is_feature_enabled, get_flag, and get_feature_value for supplied Flag values within the test scope.

Written by the indexing model from the issue text.

Description

As part of some work in the core Flagsmith repository, we found that there isn't currently a good, generic solution for mocking the flagsmith client to return a given value for a flag at a given time. The ideal implementation as I see it would be to build a fixture that can be used as a context manager, or a function that looks something like this:

def my_test_function(set_flags: FlagsmithSetFlagsFixture) -> None:
    with override_flagsmith(flags=[Flag(name="foo", enabled=True, value="foobar")]):
        # in here, any calls to Flags.is_feature_enabled,Flags.get_flag and Flags.get_feature_value 
        # for the feature "foo" will return the values provided as an argument to override_flagsmith
        ...

def my_other_test_function(set_flags: FlagsmithSetFlagsFixture) -> None:
    set_flags(flags=[Flag(name="foo", enabled=True, value="foobar")])
    
    # For the remainder of this test, any calls to Flags.is_feature_enabled,Flags.get_flag 
    # and Flags.get_feature_value for the feature "foo" will return the values provided as 
    # an argument to override_flagsmith

See PR here for more context / discussions

Dominant language
Python
Stars
24
Forks
12
Avg merge
15h 43m
Merged PRs (30d)
4

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Flagsmith/flagsmith-python-client

All issues in Flagsmith/flagsmith-python-client

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.