Skip to content

"Injecting" vs patching of built-ins/libraries #101

@nskmda

Description

@nskmda

Team,

Is there any way to 'inject' a class attribute when a 'static' reference is used for the dependency.

Example:

class Configuration:
    _BUCKET_NAME = os.getenv('BUCKET', '')
    _USERS_TABLE_NAME = os.getenv('USERS_TABLE', None)
    _S3_BUCKET = boto3.client('s3')
    _DYNAMO_DB = boto3.resource('dynamodb')

    def bucketName(self):
         return self._BUCKET_NAME

    # other code in the class follows

I would like to have these values overridden in a test spec.
so far i have to 'manually' override these values in the spec:

@inject.params(config=Configuration)
def feature_constructedWithMocks(config=None):
   config._BUCKET_NAME = injectedBucketMock
   assert injectedBucketMock == config.bucketName()

which would be nice to do 'automagically'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions