|
13 | 13 | from __future__ import absolute_import
|
14 | 14 |
|
15 | 15 | import unittest
|
| 16 | + |
16 | 17 | from mock import Mock, patch
|
17 | 18 |
|
18 |
| -from sagemaker.workflow.notebook_job_step import NotebookJobStep |
19 | 19 | from sagemaker.workflow.functions import Join
|
| 20 | +from sagemaker.workflow.notebook_job_step import NotebookJobStep |
20 | 21 |
|
21 | 22 | REGION = "us-west-2"
|
22 | 23 | PIPELINE_NAME = "test-pipeline-name"
|
@@ -573,3 +574,62 @@ def _create_step_with_required_fields(self):
|
573 | 574 | image_uri=IMAGE_URI,
|
574 | 575 | kernel_name=KERNEL_NAME,
|
575 | 576 | )
|
| 577 | + |
| 578 | + def test_environment_variables_not_shared(self): |
| 579 | + """Test that environment variables are not shared between NotebookJob steps""" |
| 580 | + # Setup shared environment variables |
| 581 | + shared_env_vars = {"test": "test"} |
| 582 | + |
| 583 | + # Create two steps with the same environment variables dictionary |
| 584 | + step1 = NotebookJobStep( |
| 585 | + name="step1", |
| 586 | + input_notebook=INPUT_NOTEBOOK, |
| 587 | + image_uri=IMAGE_URI, |
| 588 | + kernel_name=KERNEL_NAME, |
| 589 | + environment_variables=shared_env_vars, |
| 590 | + ) |
| 591 | + |
| 592 | + step2 = NotebookJobStep( |
| 593 | + name="step2", |
| 594 | + input_notebook=INPUT_NOTEBOOK, |
| 595 | + image_uri=IMAGE_URI, |
| 596 | + kernel_name=KERNEL_NAME, |
| 597 | + environment_variables=shared_env_vars, |
| 598 | + ) |
| 599 | + |
| 600 | + # Get the arguments for both steps |
| 601 | + step1_args = step1.arguments |
| 602 | + step2_args = step2.arguments |
| 603 | + |
| 604 | + # Verify that the environment variables are different objects |
| 605 | + self.assertIsNot( |
| 606 | + step1_args["Environment"], |
| 607 | + step2_args["Environment"], |
| 608 | + "Environment dictionaries should be different objects", |
| 609 | + ) |
| 610 | + |
| 611 | + # Verify that modifying one step's environment doesn't affect the other |
| 612 | + step1_env = step1_args["Environment"] |
| 613 | + step2_env = step2_args["Environment"] |
| 614 | + |
| 615 | + # Both should have the original test value |
| 616 | + self.assertEqual(step1_env["test"], "test") |
| 617 | + self.assertEqual(step2_env["test"], "test") |
| 618 | + |
| 619 | + # Modify step1's environment |
| 620 | + step1_env["test"] = "modified" |
| 621 | + |
| 622 | + # Verify step2's environment remains unchanged |
| 623 | + self.assertEqual(step2_env["test"], "test") |
| 624 | + |
| 625 | + # Verify notebook names are correct for each step |
| 626 | + self.assertEqual( |
| 627 | + step1_env["SM_INPUT_NOTEBOOK_NAME"], |
| 628 | + os.path.basename(INPUT_NOTEBOOK), |
| 629 | + "Step 1 should have its own notebook name", |
| 630 | + ) |
| 631 | + self.assertEqual( |
| 632 | + step2_env["SM_INPUT_NOTEBOOK_NAME"], |
| 633 | + os.path.basename(INPUT_NOTEBOOK), |
| 634 | + "Step 2 should have its own notebook name", |
| 635 | + ) |
0 commit comments