will resolve the sensor into run requests, but will not actually execute the run
I've noticed we've been getting a lot of questions about this.
Does this add a lot on top of sensor.get_execution_data(SensorExecutionContext())?
I wonder if the solution just requires:
- Making it possible to construct construct a SensorExecutionContext without a DagsterInstance
I don't think instance should be optional on the context.
Why not? I suspect <50% of implementations will use it.
FWIW for IOManagers we've purposely made most of the fields on the context optional so that users can test them with less boilerplate.
Definitely a little hand-wavy, so not a hard opinion here, but constructing a context feels like a leaked implementation abstraction. In my head, a context is an object constructed by the framework that makes things available to the solid during normal execution. Having an abstraction layer purely for testing seems reasonable.
Is the concern here just code duplication?
Sorry for the delay here. My main concern here is that evaluate_sensor is another API that users will need to look up and remember. If someone is writing a sensor, they're already dealing with the ScheduleExecutionContext API and SensorDefinition APIs.
My other concern is about consistency with other testing APIs. E.g. for IOManagers, our current recommended practice is to construct an OutputContext or InputContext and pass it in to the IOManager. Not necessarily saying that's the write way, but I'm concerned about introducing a new API that entrenches the gap.
Yeah I think the core point of contention is whether or not the constructor for contexts should be considered private. I think they should. We could even go the point where we change *Context classes to be abstract classes only.
Making the context construction private sounds reasonable to me.
In my mind, the question is between these two:
def my_test(): context = SensorExecutionContext.create_for_test(instance=..., last_run_key=..., last_completion_time=...) run_requests = my_sensor.get_execution_data(context) ...
(maybe get_execution_data would read better as evaluate or get_run_requests?)
def my_test(): run_requests = evaluate_sensor(my_sensor, instance=..., last_run_key=..., last_completion_time=...) ...