Hi guys! I am trying to test a composite_solid and...
# announcements
i
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
composite solids are evaluated at init time so monkey patching after they are defined won’t work
i
Ah, okay, understood. Is there a way to mock solids within composites at all?
a
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
Cool. Thanks a lot, alex! This is helpful.