It is possible to mock the op context when testing...
# ask-community
j
It is possible to mock the op context when testing a single operations. How can that be done when testing the job that runs this operation? I can pass in a RunConfig that I can parametrize with resources. Is there a way to pass in the context there as well?
s
Hi @Johannes Müller - are you saying that
build_op_context
doesn't provide enough flexibility? If not, does passing in a
MagicMock
when invoking the op work? If not, mind filing a Github issue with an example of what you'd like to work?
j
Hi sandy,
build_op_context
should work nicely. I think I am missing the step on how to pass that context to a job I am testing:
Copy code
my_context = build_op_context()
my_job.execute_in_process( # <-- How do I pass the op context here?
    run_config=RunConfig(resources={'slack': DummyResource()})
)
Copy code
@job(
    resource_defs={
        "slack": slack_resource.configured({"token": "xoxb-123456"}),
    },
    hooks={slack_message_on_failure},
)
def my_job():
    my_op_with_context()
s
Ahh I see - you might be able to pass that with direct invocation of a single op function, but there isn't a way to do it with
execute_in_process