Skip to content

Commit eeeff39

Browse files
committed
Fix unit tests
1 parent b9224d6 commit eeeff39

File tree

8 files changed

+37
-57
lines changed

8 files changed

+37
-57
lines changed

tests/unit/config/test_compiler.py

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ def test_compiling_pipeline_with_invalid_run_name_fails(
3434
):
3535
"""Tests that compiling a pipeline with an invalid run name fails."""
3636
pipeline_instance = empty_pipeline
37-
with pipeline_instance:
38-
pipeline_instance.entrypoint()
37+
pipeline_instance.prepare()
3938
with pytest.raises(ValueError):
4039
Compiler().compile(
4140
pipeline=pipeline_instance,
@@ -54,8 +53,7 @@ def _no_step_pipeline():
5453
def test_compiling_pipeline_without_steps_fails(local_stack):
5554
"""Tests that compiling a pipeline without steps fails."""
5655
pipeline_instance = _no_step_pipeline
57-
with pipeline_instance:
58-
pipeline_instance.entrypoint()
56+
pipeline_instance.prepare()
5957
with pytest.raises(ValueError):
6058
Compiler().compile(
6159
pipeline=pipeline_instance,
@@ -71,8 +69,7 @@ def test_compiling_pipeline_with_missing_step_operator(
7169
pipeline_instance = one_step_pipeline(
7270
empty_step.configure(step_operator="s")
7371
)
74-
with pipeline_instance:
75-
pipeline_instance.entrypoint()
72+
pipeline_instance.prepare()
7673
with pytest.raises(StackValidationError):
7774
Compiler().compile(
7875
pipeline=pipeline_instance,
@@ -89,8 +86,7 @@ def test_compiling_pipeline_with_missing_experiment_tracker(
8986
pipeline_instance = one_step_pipeline(
9087
empty_step.configure(experiment_tracker="e")
9188
)
92-
with pipeline_instance:
93-
pipeline_instance.entrypoint()
89+
pipeline_instance.prepare()
9490
with pytest.raises(StackValidationError):
9591
Compiler().compile(
9692
pipeline=pipeline_instance,
@@ -113,8 +109,7 @@ def test_pipeline_and_steps_dont_get_modified_during_compilation(
113109
"_empty_step": StepConfigurationUpdate(extra={"key": "new_value"})
114110
},
115111
)
116-
with pipeline_instance:
117-
pipeline_instance.entrypoint()
112+
pipeline_instance.prepare()
118113
Compiler().compile(
119114
pipeline=pipeline_instance,
120115
stack=local_stack,
@@ -148,8 +143,7 @@ def pipeline_instance():
148143
empty_step(id="step_1")
149144
empty_step(id="step_2", after="step_1")
150145

151-
with pipeline_instance:
152-
pipeline_instance.entrypoint()
146+
pipeline_instance.prepare()
153147
snapshot = Compiler().compile(
154148
pipeline=pipeline_instance,
155149
stack=local_stack,
@@ -204,8 +198,7 @@ class StubSettings(BaseSettings):
204198
)
205199
},
206200
)
207-
with pipeline_instance:
208-
pipeline_instance.entrypoint()
201+
pipeline_instance.prepare()
209202
snapshot = Compiler().compile(
210203
pipeline=pipeline_instance,
211204
stack=local_stack,
@@ -252,8 +245,7 @@ def test_general_settings_merging(one_step_pipeline, empty_step, local_stack):
252245
)
253246
},
254247
)
255-
with pipeline_instance:
256-
pipeline_instance.entrypoint()
248+
pipeline_instance.prepare()
257249
snapshot = Compiler().compile(
258250
pipeline=pipeline_instance,
259251
stack=local_stack,
@@ -299,8 +291,7 @@ def test_extra_merging(one_step_pipeline, empty_step, local_stack):
299291
steps={"_empty_step": StepConfigurationUpdate(extra=run_step_extra)},
300292
)
301293

302-
with pipeline_instance:
303-
pipeline_instance.entrypoint()
294+
pipeline_instance.prepare()
304295

305296
snapshot = Compiler().compile(
306297
pipeline=pipeline_instance,
@@ -358,8 +349,7 @@ def test_success_hook_merging(
358349
},
359350
)
360351

361-
with pipeline_instance:
362-
pipeline_instance.entrypoint()
352+
pipeline_instance.prepare()
363353
snapshot = Compiler().compile(
364354
pipeline=pipeline_instance,
365355
stack=local_stack,
@@ -409,8 +399,7 @@ def test_failure_hook_merging(
409399
},
410400
)
411401

412-
with pipeline_instance:
413-
pipeline_instance.entrypoint()
402+
pipeline_instance.prepare()
414403
snapshot = Compiler().compile(
415404
pipeline=pipeline_instance,
416405
stack=local_stack,
@@ -453,8 +442,7 @@ def test_stack_component_settings_for_missing_component_are_ignored(
453442
steps={"_empty_step": StepConfigurationUpdate(settings=settings)},
454443
)
455444

456-
with pipeline_instance:
457-
pipeline_instance.entrypoint()
445+
pipeline_instance.prepare()
458446
snapshot = Compiler().compile(
459447
pipeline=pipeline_instance,
460448
stack=local_stack,
@@ -500,8 +488,7 @@ class StubSettings(BaseSettings):
500488
steps={"_empty_step": StepConfigurationUpdate(settings=settings)},
501489
)
502490

503-
with pipeline_instance:
504-
pipeline_instance.entrypoint()
491+
pipeline_instance.prepare()
505492
snapshot = Compiler().compile(
506493
pipeline=pipeline_instance,
507494
stack=local_stack,
@@ -551,8 +538,7 @@ class StubSettings(BaseSettings):
551538
steps={"_empty_step": StepConfigurationUpdate(settings=settings)},
552539
)
553540

554-
with pipeline_instance:
555-
pipeline_instance.entrypoint()
541+
pipeline_instance.prepare()
556542
snapshot = Compiler().compile(
557543
pipeline=pipeline_instance,
558544
stack=local_stack,
@@ -585,8 +571,7 @@ def test_spec_compilation(local_stack):
585571
def pipeline_instance():
586572
s2(s1())
587573

588-
with pipeline_instance:
589-
pipeline_instance.entrypoint()
574+
pipeline_instance.prepare()
590575
spec = (
591576
Compiler()
592577
.compile(
@@ -652,8 +637,7 @@ class StubSettings(BaseSettings):
652637
settings={"orchestrator": shortcut_settings}
653638
)
654639

655-
with pipeline_instance_with_shortcut_settings:
656-
pipeline_instance_with_shortcut_settings.entrypoint()
640+
pipeline_instance_with_shortcut_settings.prepare()
657641

658642
with does_not_raise():
659643
snapshot = Compiler().compile(
@@ -677,8 +661,7 @@ class StubSettings(BaseSettings):
677661
}
678662
)
679663

680-
with pipeline_instance_with_duplicate_settings:
681-
pipeline_instance_with_duplicate_settings.entrypoint()
664+
pipeline_instance_with_duplicate_settings.prepare()
682665

683666
with pytest.raises(ValueError):
684667
snapshot = Compiler().compile(

tests/unit/conftest.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,6 @@ def step_context_with_no_output(
294294
sample_pipeline_run: PipelineRunResponse,
295295
sample_step_run: StepRunResponse,
296296
) -> StepContext:
297-
StepContext._clear()
298297
return StepContext(
299298
pipeline_run=sample_pipeline_run,
300299
step_run=sample_step_run,
@@ -312,7 +311,6 @@ def step_context_with_single_output(
312311
materializers = {"output_1": (BaseMaterializer,)}
313312
artifact_uris = {"output_1": ""}
314313
artifact_configs = {"output_1": None}
315-
StepContext._clear()
316314
return StepContext(
317315
pipeline_run=sample_pipeline_run,
318316
step_run=sample_step_run,
@@ -337,7 +335,6 @@ def step_context_with_two_outputs(
337335
}
338336
artifact_configs = {"output_1": None, "output_2": None}
339337

340-
StepContext._clear()
341338
return StepContext(
342339
pipeline_run=sample_pipeline_run,
343340
step_run=sample_step_run,
@@ -634,6 +631,7 @@ def sample_snapshot_response_model(
634631
updated=datetime.now(),
635632
runnable=True,
636633
deployable=True,
634+
is_dynamic=False,
637635
),
638636
metadata=PipelineSnapshotResponseMetadata(
639637
run_name_template="",

tests/unit/entrypoints/test_base_entrypoint_configuration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,4 @@ def test_loading_the_snapshot(clean_client):
6969
arguments=["--snapshot_id", str(snapshot.id)]
7070
)
7171

72-
assert entrypoint_config.load_snapshot() == snapshot
72+
assert entrypoint_config.snapshot == snapshot

tests/unit/orchestrators/test_publish_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ def test_pipeline_run_status_computation(
100100
run_status=ExecutionStatus.RUNNING,
101101
step_statuses=step_statuses,
102102
num_steps=num_steps,
103+
is_dynamic_pipeline=False,
103104
)
104105
== expected_run_status
105106
)

tests/unit/orchestrators/test_step_runner.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@
2222
from zenml.config.step_configurations import Step
2323
from zenml.config.step_run_info import StepRunInfo
2424
from zenml.enums import ArtifactSaveType
25-
from zenml.models import PipelineRunResponse, StepRunResponse
25+
from zenml.models import (
26+
PipelineRunResponse,
27+
PipelineSnapshotResponse,
28+
StepRunResponse,
29+
)
2630
from zenml.orchestrators.step_launcher import StepRunner
2731
from zenml.stack import Stack
2832
from zenml.steps import step
@@ -43,6 +47,7 @@ def test_running_a_successful_step(
4347
local_stack,
4448
sample_pipeline_run: PipelineRunResponse,
4549
sample_step_run: StepRunResponse,
50+
sample_snapshot_response_model: PipelineSnapshotResponse,
4651
):
4752
"""Tests that running a successful step runs the step entrypoint
4853
and correctly prepares/cleans up."""
@@ -74,7 +79,9 @@ def test_running_a_successful_step(
7479
run_name="run_name",
7580
pipeline_step_name="step_name",
7681
config=step.config,
82+
spec=step.spec,
7783
pipeline=pipeline_config,
84+
snapshot=sample_snapshot_response_model,
7885
force_write_logs=lambda: None,
7986
)
8087

@@ -98,6 +105,7 @@ def test_running_a_failing_step(
98105
local_stack,
99106
sample_pipeline_run: PipelineRunResponse,
100107
sample_step_run: StepRunResponse,
108+
sample_snapshot_response_model: PipelineSnapshotResponse,
101109
):
102110
"""Tests that running a failing step runs the step entrypoint
103111
and correctly prepares/cleans up."""
@@ -130,7 +138,9 @@ def test_running_a_failing_step(
130138
run_name="run_name",
131139
pipeline_step_name="step_name",
132140
config=step.config,
141+
spec=step.spec,
133142
pipeline=pipeline_config,
143+
snapshot=sample_snapshot_response_model,
134144
force_write_logs=lambda: None,
135145
)
136146

tests/unit/pipelines/test_base_pipeline.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,7 @@ def test_compiling_a_pipeline_merges_schedule(
429429
config_path.write_text(run_config.yaml())
430430

431431
pipeline_instance = empty_pipeline
432-
with pipeline_instance:
433-
pipeline_instance.entrypoint()
432+
pipeline_instance.prepare()
434433

435434
_, schedule, _ = pipeline_instance._compile(
436435
config_path=str(config_path),
@@ -462,8 +461,7 @@ def test_compiling_a_pipeline_merges_build(
462461
in_code_build_id = uuid4()
463462

464463
pipeline_instance = empty_pipeline
465-
with pipeline_instance:
466-
pipeline_instance.entrypoint()
464+
pipeline_instance.prepare()
467465

468466
# Config with ID
469467
_, _, build = pipeline_instance._compile(

tests/unit/stack/test_stack.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,7 @@ def test_stack_submission(
149149
components."""
150150
# Mock the pipeline run registering which tries (and fails) to serialize
151151
# our mock objects
152-
with empty_pipeline:
153-
empty_pipeline.entrypoint()
152+
empty_pipeline.prepare()
154153
snapshot = Compiler().compile(
155154
pipeline=empty_pipeline,
156155
stack=stack_with_mock_components,

tests/unit/steps/test_step_context.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,15 @@
2222
from zenml.steps import StepContext
2323

2424

25-
def test_step_context_is_singleton(step_context_with_no_output):
26-
"""Tests that the step context is a singleton."""
27-
assert StepContext() is step_context_with_no_output
28-
29-
3025
def test_get_step_context(step_context_with_no_output):
3126
"""Unit test for `get_step_context()`."""
3227

33-
# step context exists -> returns the step context
34-
assert get_step_context() is StepContext()
35-
36-
# step context does not exist -> raises an exception
37-
StepContext._clear()
3828
with pytest.raises(RuntimeError):
3929
get_step_context()
4030

31+
with step_context_with_no_output:
32+
assert get_step_context() is step_context_with_no_output
33+
4134

4235
def test_initialize_step_context_with_mismatched_keys(
4336
sample_pipeline_run,
@@ -49,7 +42,6 @@ def test_initialize_step_context_with_mismatched_keys(
4942
artifact_configs = {"some_yet_another_output_name": None}
5043

5144
with pytest.raises(StepContextError):
52-
StepContext._clear()
5345
StepContext(
5446
pipeline_run=sample_pipeline_run,
5547
step_run=sample_step_run,
@@ -69,7 +61,6 @@ def test_initialize_step_context_with_matching_keys(
6961
artifact_configs = {"some_output_name": None}
7062

7163
with does_not_raise():
72-
StepContext._clear()
7364
StepContext(
7465
pipeline_run=sample_pipeline_run,
7566
step_run=sample_step_run,

0 commit comments

Comments
 (0)