Skip to content

Resource mocking for solid testing #3329

Answered by schrockn
vilhub asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @vilhub this is pretty much the best approach given the APIs we have today.

This is what I would do (without the pytest parameterization, which I think is the source of some of the convolution here):

from dagster import ResourceDefinition, ModeDefinition, solid, execute_solid


class MockService:
    def compute(self, *_, **__):
        return "mock value"


@solid(required_resource_keys={"service"})
def solid_to_test(context):
    return context.resources.service.compute()


def make_mock_def(**resource_instances):
    return ModeDefinition(
        resource_defs={
            key: ResourceDefinition.hardcoded_resource(resource_instance)
            for key, resource_instance in reso…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@vilhub
Comment options

@mgasner
Comment options

@vilhub
Comment options

Answer selected by vilhub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants