https://dagster.io/ logo
#announcements
Title
# announcements
i

Ignacio Funke

10/16/2020, 4:24 PM
Hi guys! I am trying to test a composite_solid and mock a solid within it. I am using monkeypatch mechanism from pytest to replace the solid. However, it does not seem like the patch is working. Do you know how to solve the problem? A sample code is as follows:
Copy code
def test_my_test(monkeypatch):
    @solid
    def mock_my_solid(_):
        yield Output(pd.DataFrame({
            "date": pd.to_datetime(["2020-05-01", datetime.today()]),
            "name": ["One", "Two"]
        }))

    monkeypatch.setattr("mymodule.my_solid", mock_my_solid)

    result = execute_solid(my_composite_solid_using_my_solid)
    out = result.output_for_solid("my_solid")  # This returns the original output from my_solid
a

alex

10/16/2020, 4:38 PM
composite solids are evaluated at init time so monkey patching after they are defined won’t work
i

Ignacio Funke

10/16/2020, 4:43 PM
Ah, okay, understood. Is there a way to mock solids within composites at all?
a

alex

10/16/2020, 4:50 PM
hmm not really if its defined at module scope - maybe make the composite solid an output of a function, then you can mock before you invoke the function
i

Ignacio Funke

10/16/2020, 4:51 PM
Cool. Thanks a lot, alex! This is helpful.