constants = make_values_resource( gcs_prefix=F...
# ask-ai
d
constants = make_values_resource( gcs_prefix=Field( str, default_value=“gs://prefix/” description=“GCS prefix”, ), ) @asset( resource_defs={“constants”: constants}, … ) I’m passing a resource like this, how do I change the value of the constant in my pytest test?
s
To change the value of a resource in a pytest test, you can directly pass the desired configuration when constructing the context for the asset. The
build_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:
Copy code
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.