-
Is there a way to write a test for a dagster pipeline with a mock value for the first asset? Keywords: input value input_values |
Beta Was this translation helpful? Give feedback.
Answered by
sryza
Mar 20, 2024
Replies: 2 comments 3 replies
-
One way to do this is with a function that generates a source asset with an IO manager that returns the value you want to mock in. from dagster import IOManager, SourceAsset
def mock_asset(asset_key, value):
class MockIOManager(IOManager):
def load_input(self, context):
return value
def handle_output(self, context, obj):
raise NotImplementedError()
return SourceAsset(key=asset_key, io_manager_def=MockIOManager()) Example usage: from dagster import asset, materialize
@asset
def asset2(asset1):
return asset1 + 1
result = materialize(assets=[asset2, mock_asset("asset1", 5)])
assert result.asset_value(asset2.key) == 6 |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
sryza
-
How can I do this using AssetSpec instead of SourceAsset (since it is going to be deprecated)? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
One way to do this is with a function that generates a source asset with an IO manager that returns the value you want to mock in.
Example usage: