https://dagster.io/ logo
Title
y

Yang

10/25/2022, 7:59 PM
hello! question about mocking resources. I have a mock resource set up like this
@resource()
def mocked_bigquery_extra_primary_fund():
    res = MagicMock()

    three_funds = pd.DataFrame({
        'id': [0,2, 4],
        'isin': ["123", "234", None],
        'name': ["best fund", "bestest fund", "new primary fund"],
        'ric': ["32", "a5", None],
        'cusip': ["ss", "bb", None],
        'sedol': ["as", "fj", None],
        'ticker': ["BF", "BTF", None], 
        'instrument_perm_id': ["3", "5", "4"],
        'fund_shareclass_id': [6, 33, 9],
        'fund_primary_shareclass_id': [9, 33, 9],
        'lipper_fund_parent_id': ["3422", "999", "444"],
        "lipper_fund_asset_universe": ["equity", "cash", "equity"],
        "lipper_fund_asset_universe_id": ["23", None, None]
        })

    res.assign_yb_id.return_value = three_funds
    return res
I want to patch another function with a function that will take one argument (not predetermined). how do I do that? thanks!
:dagster-bot-responded-by-community: 1
z

Zach

10/25/2022, 9:12 PM
is this another function on
res
that you're trying to mock? there might be a better way to do it, but usually in those cases I just overwrite the function with a new mock function:
@resource()
def mocked_bigquery_extra_primary_fund():
    res = MagicMock()

    three_funds = pd.DataFrame({
        'id': [0,2, 4],
        'isin': ["123", "234", None],
        'name': ["best fund", "bestest fund", "new primary fund"],
        'ric': ["32", "a5", None],
        'cusip': ["ss", "bb", None],
        'sedol': ["as", "fj", None],
        'ticker': ["BF", "BTF", None], 
        'instrument_perm_id': ["3", "5", "4"],
        'fund_shareclass_id': [6, 33, 9],
        'fund_primary_shareclass_id': [9, 33, 9],
        'lipper_fund_parent_id': ["3422", "999", "444"],
        "lipper_fund_asset_universe": ["equity", "cash", "equity"],
        "lipper_fund_asset_universe_id": ["23", None, None]
        })

    res.assign_yb_id.return_value = three_funds

    def mock_another_function(param):
        return "something"
    res.another_function = mock_another_function

    return res
y

Yang

10/25/2022, 9:14 PM
yes, another function of res. oh ok! I will try this, thanks
it works!
🎉 1