Hello, how can I call a sensor locally for debuggi...
# announcements
m
Hello, how can I call a sensor locally for debugging sake?
s
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
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
Ah, right. I'm going to edit that code example above
m
My sensor is a decorated function and has no methods..
s
story_recommender_sensor
is a
SensorDefinition
. the decorator returns a
SensorDefinition
, not a function
just edited one more time
m
Thanks, that works