Philippe Laflamme
08/09/2023, 5:13 PMdef test_the_sensor():
ctx = build_sensor_context(resources={"my_api": mock_api})
my_sensor(ctx)
with my_sensor
defined like so
@sensor(required_resource_keys={"my_api"})
def my_sensor(ctx):
my_api = ctx.resources.my_api
...
Running pytest
results in this:
TypeError: my_sensor() got an unexpected keyword argument 'my_api'
If I add my_api: SomeApi
to my_sensor
arguments, the test passes, but then at runtime in the real dagster instance, I get this:
TypeError: my_sensor() missing 1 required positional argument: 'my_api'
I'm running 1.13.13, is this a known issue or am I doing something wrong?yuhan
08/09/2023, 6:01 PMfrom dagster import sensor, build_sensor_context, ConfigurableResource
class MyResource(ConfigurableResource):
value: str
@sensor()
def my_sensor(my_api: MyResource):
print(my_api.value)
def test_the_sensor():
ctx = build_sensor_context(resources={"my_api": MyResource(value="foo")})
my_sensor(ctx)
this should workyuhan
08/09/2023, 6:02 PMPhilippe Laflamme
08/09/2023, 6:03 PMdef my_sensor(ctx, my_api: MyResource):
pass
the test works, but in the real runtime, I get this:
TypeError: my_sensor() missing 1 required positional argument: 'my_api'
yuhan
08/09/2023, 6:04 PMyuhan
08/09/2023, 6:31 PMfrom dagster import (
sensor,
build_sensor_context,
ConfigurableResource,
asset,
Definitions,
AssetSelection,
)
class MyResource(ConfigurableResource):
value: str
@asset
def my_asset():
return
@sensor(asset_selection=AssetSelection.all())
def my_sensor(context, my_api: MyResource):
print(my_api.value)
def test_the_sensor():
ctx = build_sensor_context(resources={"my_api": MyResource(value="foo")})
my_sensor(ctx)
defs = Definitions(
assets=[my_asset], sensors=[my_sensor], resources={"my_api": MyResource(value="foo")}
)
this is the full code snippet that i tested and it works in a real dagster instancePhilippe Laflamme
08/09/2023, 6:35 PMchris
08/09/2023, 7:45 PMPhilippe Laflamme
08/09/2023, 7:48 PMchris
08/09/2023, 7:58 PM