https://dagster.io/ logo
m

Marco

02/23/2021, 9:21 PM
Hello, how can I call a sensor locally for debugging sake?
s

sandy

02/23/2021, 9:31 PM
Here's an example of a unit test for a sensor called `story_recommender_sensor`:
Copy code
from unittest.mock import MagicMock
from dagster import DagsterInstance, SensorExecutionContext

def test_first_events():
    context = SensorExecutionContext(
        instance=MagicMock(spec=DagsterInstance),
        last_run_key=None,
        last_completion_time=None,
    )
    requests = story_recommender_sensor.get_execution_data(context)
    assert len(requests) == 1
    assert requests[0].run_key == "1|2"
Does that help?
m

Marco

02/23/2021, 9:33 PM
Thanks, let me try
So I have a couple of issues: 1. I cannot instantiate SensorExecutionContext with args
2. What type is story_reccomender_sensor?
s

sandy

02/23/2021, 9:50 PM
Ah, right. I'm going to edit that code example above
m

Marco

02/23/2021, 9:50 PM
My sensor is a decorated function and has no methods..
s

sandy

02/23/2021, 9:51 PM
story_recommender_sensor
is a
SensorDefinition
. the decorator returns a
SensorDefinition
, not a function
just edited one more time
m

Marco

02/23/2021, 10:18 PM
Thanks, that works
3 Views