-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add job/op equivalents to execution context (#7734)
Closes #6979
- Loading branch information
Showing
2 changed files
with
120 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
python_modules/dagster/dagster_tests/core_tests/execution_tests/test_context.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import pytest | ||
|
||
from dagster import OpExecutionContext, check, execute_pipeline, job, op, pipeline, solid | ||
from dagster.core.definitions.job_definition import JobDefinition | ||
from dagster.core.definitions.op_definition import OpDefinition | ||
from dagster.core.definitions.pipeline_definition import PipelineDefinition | ||
from dagster.core.definitions.solid_definition import SolidDefinition | ||
from dagster.core.execution.context.compute import SolidExecutionContext | ||
from dagster.core.storage.pipeline_run import DagsterRun, PipelineRun | ||
|
||
|
||
def test_op_execution_context(): | ||
@op | ||
def ctx_op(context: OpExecutionContext): | ||
check.inst(context.run, DagsterRun) | ||
assert context.job_name == "foo" | ||
assert context.job_def.name == "foo" | ||
check.inst(context.job_def, JobDefinition) | ||
assert context.op_config is None | ||
check.inst(context.op_def, OpDefinition) | ||
|
||
check.inst(context.pipeline_run, PipelineRun) | ||
assert context.pipeline_name == "foo" | ||
assert context.pipeline_def.name == "foo" | ||
check.inst(context.pipeline_def, PipelineDefinition) | ||
assert context.solid_config is None | ||
check.inst(context.solid_def, SolidDefinition) | ||
|
||
@job | ||
def foo(): | ||
ctx_op() | ||
|
||
assert foo.execute_in_process().success | ||
|
||
|
||
def test_solid_execution_context(): | ||
@solid | ||
def ctx_solid(context: SolidExecutionContext): | ||
check.inst(context.run, DagsterRun) | ||
assert context.job_name == "foo" | ||
|
||
with pytest.raises(Exception): | ||
context.job_def | ||
|
||
assert context.op_config is None | ||
|
||
with pytest.raises(Exception): | ||
context.op_def | ||
|
||
check.inst(context.pipeline_run, PipelineRun) | ||
assert context.pipeline_name == "foo" | ||
assert context.pipeline_def.name == "foo" | ||
check.inst(context.pipeline_def, PipelineDefinition) | ||
assert context.solid_config is None | ||
check.inst(context.solid_def, SolidDefinition) | ||
|
||
@pipeline | ||
def foo(): | ||
ctx_solid() | ||
|
||
assert execute_pipeline(foo).success |