Skip to content

Commit 5d6ca9e

Browse files
beniericroot
authored and
root
committed
fix: make unit tests compatible with pytest-xdist (aws#4486)
* fix: make unit tests compatible with pytest-xdist * fix failing test
1 parent 8a43a7b commit 5d6ca9e

File tree

8 files changed

+33
-16
lines changed

8 files changed

+33
-16
lines changed

tests/unit/sagemaker/feature_store/feature_processor/test_data_helpers.py

+14
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,20 @@
5252
"some-other-key": {"some-key": "some-value"},
5353
}
5454

55+
DATA_SOURCE_UNIQUE_ID_TOO_LONG = """
56+
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\
57+
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\
58+
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\
59+
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\
60+
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\
61+
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\
62+
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\
63+
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\
64+
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\
65+
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\
66+
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\
67+
"""
68+
5569
DESCRIBE_FEATURE_GROUP_RESPONSE = {
5670
"FeatureGroupArn": INPUT_FEATURE_GROUP_ARN,
5771
"FeatureGroupName": INPUT_FEATURE_GROUP_NAME,

tests/unit/sagemaker/feature_store/feature_processor/test_validation.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
import pytest
2020

2121
import test_data_helpers as tdh
22-
import string
23-
import random
2422
from mock import Mock
2523

2624
from sagemaker.feature_store.feature_processor._validation import (
@@ -164,7 +162,7 @@ def invalid_spark_position(spark, fg_data_source, s3_data_source):
164162
("", "unique_id", "data_source_name of input does not match pattern '.*'."),
165163
(
166164
"source",
167-
"".join(random.choices(string.ascii_uppercase, k=2050)),
165+
tdh.DATA_SOURCE_UNIQUE_ID_TOO_LONG,
168166
"data_source_unique_id of input does not match pattern '.*'.",
169167
),
170168
("source", "", "data_source_unique_id of input does not match pattern '.*'."),

tests/unit/sagemaker/remote_function/core/test_stored_function.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939

4040
from sagemaker.workflow.function_step import _FunctionStep, DelayedReturn
4141
from sagemaker.workflow.parameters import ParameterFloat
42-
from sagemaker.utils import sagemaker_timestamp
4342

4443
from tests.unit.sagemaker.experiments.helpers import (
4544
TEST_EXP_DISPLAY_NAME,
@@ -55,7 +54,7 @@
5554
FUNCTION_FOLDER = "function"
5655
ARGUMENT_FOLDER = "arguments"
5756
RESULT_FOLDER = "results"
58-
PIPELINE_BUILD_TIME = sagemaker_timestamp()
57+
PIPELINE_BUILD_TIME = "2022-05-10T17:30:20Z"
5958

6059
mock_s3 = {}
6160

tests/unit/sagemaker/training_compiler/test_huggingface_pytorch_compiler.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def test_unsupported_cpu_instance(
202202
).fit()
203203

204204

205-
@pytest.mark.parametrize("unsupported_gpu_instance_class", UNSUPPORTED_GPU_INSTANCE_CLASSES)
205+
@pytest.mark.parametrize("unsupported_gpu_instance_class", sorted(UNSUPPORTED_GPU_INSTANCE_CLASSES))
206206
def test_unsupported_gpu_instance(
207207
unsupported_gpu_instance_class,
208208
huggingface_training_compiler_version,
@@ -366,7 +366,7 @@ def test_unsupported_distribution(
366366
@patch("sagemaker.utils.create_tar_file", MagicMock())
367367
@patch("sagemaker.estimator.name_from_base", return_value=JOB_NAME)
368368
@patch("time.time", return_value=TIME)
369-
@pytest.mark.parametrize("instance_class", SUPPORTED_GPU_INSTANCE_CLASSES)
369+
@pytest.mark.parametrize("instance_class", sorted(SUPPORTED_GPU_INSTANCE_CLASSES))
370370
def test_pytorchxla_distribution(
371371
time,
372372
name_from_base,
@@ -430,7 +430,7 @@ def test_pytorchxla_distribution(
430430
@patch("sagemaker.utils.create_tar_file", MagicMock())
431431
@patch("sagemaker.estimator.name_from_base", return_value=JOB_NAME)
432432
@patch("time.time", return_value=TIME)
433-
@pytest.mark.parametrize("instance_class", SUPPORTED_GPU_INSTANCE_CLASSES)
433+
@pytest.mark.parametrize("instance_class", sorted(SUPPORTED_GPU_INSTANCE_CLASSES))
434434
def test_default_compiler_config(
435435
time,
436436
name_from_base,

tests/unit/sagemaker/training_compiler/test_huggingface_tensorflow_compiler.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def test_unsupported_cpu_instance(
201201
).fit()
202202

203203

204-
@pytest.mark.parametrize("unsupported_gpu_instance_class", UNSUPPORTED_GPU_INSTANCE_CLASSES)
204+
@pytest.mark.parametrize("unsupported_gpu_instance_class", sorted(UNSUPPORTED_GPU_INSTANCE_CLASSES))
205205
def test_unsupported_gpu_instance(
206206
unsupported_gpu_instance_class,
207207
huggingface_training_compiler_version,
@@ -315,7 +315,7 @@ def test_unsupported_distribution(
315315
@patch("sagemaker.utils.create_tar_file", MagicMock())
316316
@patch("sagemaker.estimator.name_from_base", return_value=JOB_NAME)
317317
@patch("time.time", return_value=TIME)
318-
@pytest.mark.parametrize("instance_class", SUPPORTED_GPU_INSTANCE_CLASSES)
318+
@pytest.mark.parametrize("instance_class", sorted(SUPPORTED_GPU_INSTANCE_CLASSES))
319319
def test_default_compiler_config(
320320
time,
321321
name_from_base,

tests/unit/sagemaker/training_compiler/test_pytorch_compiler.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def test_unsupported_cpu_instance(cpu_instance_type, pytorch_training_compiler_v
191191
).fit()
192192

193193

194-
@pytest.mark.parametrize("unsupported_gpu_instance_class", UNSUPPORTED_GPU_INSTANCE_CLASSES)
194+
@pytest.mark.parametrize("unsupported_gpu_instance_class", sorted(UNSUPPORTED_GPU_INSTANCE_CLASSES))
195195
def test_unsupported_gpu_instance(
196196
unsupported_gpu_instance_class, pytorch_training_compiler_version
197197
):
@@ -309,7 +309,7 @@ def test_unsupported_distribution(
309309
@patch("sagemaker.utils.create_tar_file", MagicMock())
310310
@patch("sagemaker.estimator.name_from_base", return_value=JOB_NAME)
311311
@patch("time.time", return_value=TIME)
312-
@pytest.mark.parametrize("instance_class", SUPPORTED_GPU_INSTANCE_CLASSES)
312+
@pytest.mark.parametrize("instance_class", sorted(SUPPORTED_GPU_INSTANCE_CLASSES))
313313
def test_pytorchxla_distribution(
314314
time,
315315
name_from_base,
@@ -372,7 +372,7 @@ def test_pytorchxla_distribution(
372372
@patch("sagemaker.utils.create_tar_file", MagicMock())
373373
@patch("sagemaker.estimator.name_from_base", return_value=JOB_NAME)
374374
@patch("time.time", return_value=TIME)
375-
@pytest.mark.parametrize("instance_class", SUPPORTED_GPU_INSTANCE_CLASSES)
375+
@pytest.mark.parametrize("instance_class", sorted(SUPPORTED_GPU_INSTANCE_CLASSES))
376376
def test_default_compiler_config(
377377
time,
378378
name_from_base,

tests/unit/sagemaker/training_compiler/test_tensorflow_compiler.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,9 @@ def test_cpu_instance(
176176
compiler_config=TrainingCompilerConfig(),
177177
).fit()
178178

179-
@pytest.mark.parametrize("unsupported_gpu_instance_class", UNSUPPORTED_GPU_INSTANCE_CLASSES)
179+
@pytest.mark.parametrize(
180+
"unsupported_gpu_instance_class", sorted(UNSUPPORTED_GPU_INSTANCE_CLASSES)
181+
)
180182
def test_gpu_instance(
181183
self,
182184
unsupported_gpu_instance_class,
@@ -254,7 +256,7 @@ def test_python_2(self, tensorflow_training_version):
254256
@patch("sagemaker.estimator.name_from_base", return_value=JOB_NAME)
255257
@patch("time.time", return_value=TIME)
256258
class TestTrainingCompilerConfig:
257-
@pytest.mark.parametrize("instance_class", SUPPORTED_GPU_INSTANCE_CLASSES)
259+
@pytest.mark.parametrize("instance_class", sorted(SUPPORTED_GPU_INSTANCE_CLASSES))
258260
def test_default(
259261
self,
260262
time,
@@ -308,7 +310,7 @@ def test_default(
308310
actual_train_args == expected_train_args
309311
), f"{json.dumps(actual_train_args, indent=2)} != {json.dumps(expected_train_args, indent=2)}"
310312

311-
@pytest.mark.parametrize("instance_class", SUPPORTED_GPU_INSTANCE_CLASSES)
313+
@pytest.mark.parametrize("instance_class", sorted(SUPPORTED_GPU_INSTANCE_CLASSES))
312314
def test_byoc(
313315
self,
314316
time,

tests/unit/sagemaker/workflow/test_training_step.py

+4
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@
263263
Join(on="/", values=["s3://my-bucket", "my-input"]),
264264
]
265265

266+
OUTPUT_PARAM_LIST = ["s3://my-bucket/my-output-path", ParameterString(name="OutputPath")]
267+
266268

267269
@pytest.fixture
268270
def training_input():
@@ -454,6 +456,7 @@ def test_training_step_estimator_with_param_code_input(
454456
assert step_def == step_def2
455457

456458

459+
@pytest.mark.skip(reason="incompatible with pytest-xdist")
457460
@pytest.mark.parametrize("estimator", ESTIMATOR_LISTS)
458461
@pytest.mark.parametrize("training_input", INPUT_PARAM_LISTS)
459462
@pytest.mark.parametrize(
@@ -523,6 +526,7 @@ def test_training_step_with_framework_estimator(
523526
assert step_def == step_def2
524527

525528

529+
@pytest.mark.skip(reason="incompatible with pytest-xdist")
526530
@patch("sagemaker.workflow.utilities._pipeline_config", MOCKED_PIPELINE_CONFIG)
527531
@pytest.mark.parametrize("estimator", ESTIMATOR_LISTS_LOCAL_CODE)
528532
@pytest.mark.parametrize("training_input", INPUT_PARAM_LISTS)

0 commit comments

Comments
 (0)