David de Meij
02/27/2024, 4:36 PMScout
02/27/2024, 4:36 PMbuild_asset_context
function from Dagster can be used to create a context for testing assets, and it allows you to specify resource configurations. Here's an example based on the documentation on how you might change the value of the constants
resource in a pytest test: python from dagster import build_asset_context def test_my_asset(): context = build_asset_context(resources={"constants": {"gcs_prefix": "<gs://new_prefix/>"}}) result = my_asset(context) # Your assertions here
In this example, build_asset_context
is used to create a context with the constants
resource, and the gcs_prefix
is set to "<gs://new_prefix/>"
. This configuration will be used when the my_asset
function is called within the test. Remember to replace my_asset
with the actual name of your asset function and add any necessary assertions to validate the behavior of your asset under the test conditions.