Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make unit tests compatible with pytest-xdist #4486

Merged
merged 3 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import pytest

import test_data_helpers as tdh
import string
import random
from mock import Mock

from sagemaker.feature_store.feature_processor._validation import (
Expand Down Expand Up @@ -164,7 +162,7 @@ def invalid_spark_position(spark, fg_data_source, s3_data_source):
("", "unique_id", "data_source_name of input does not match pattern '.*'."),
(
"source",
"".join(random.choices(string.ascii_uppercase, k=2050)),
"ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ",
"data_source_unique_id of input does not match pattern '.*'.",
),
("source", "", "data_source_unique_id of input does not match pattern '.*'."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@

from sagemaker.workflow.function_step import _FunctionStep, DelayedReturn
from sagemaker.workflow.parameters import ParameterFloat
from sagemaker.utils import sagemaker_timestamp

from tests.unit.sagemaker.experiments.helpers import (
TEST_EXP_DISPLAY_NAME,
Expand All @@ -55,7 +54,7 @@
FUNCTION_FOLDER = "function"
ARGUMENT_FOLDER = "arguments"
RESULT_FOLDER = "results"
PIPELINE_BUILD_TIME = sagemaker_timestamp()
PIPELINE_BUILD_TIME = "2022-05-10T17:30:20Z"

mock_s3 = {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def test_unsupported_cpu_instance(
).fit()


@pytest.mark.parametrize("unsupported_gpu_instance_class", UNSUPPORTED_GPU_INSTANCE_CLASSES)
@pytest.mark.parametrize("unsupported_gpu_instance_class", sorted(UNSUPPORTED_GPU_INSTANCE_CLASSES))
def test_unsupported_gpu_instance(
unsupported_gpu_instance_class,
huggingface_training_compiler_version,
Expand Down Expand Up @@ -366,7 +366,7 @@ def test_unsupported_distribution(
@patch("sagemaker.utils.create_tar_file", MagicMock())
@patch("sagemaker.estimator.name_from_base", return_value=JOB_NAME)
@patch("time.time", return_value=TIME)
@pytest.mark.parametrize("instance_class", SUPPORTED_GPU_INSTANCE_CLASSES)
@pytest.mark.parametrize("instance_class", sorted(SUPPORTED_GPU_INSTANCE_CLASSES))
def test_pytorchxla_distribution(
time,
name_from_base,
Expand Down Expand Up @@ -430,7 +430,7 @@ def test_pytorchxla_distribution(
@patch("sagemaker.utils.create_tar_file", MagicMock())
@patch("sagemaker.estimator.name_from_base", return_value=JOB_NAME)
@patch("time.time", return_value=TIME)
@pytest.mark.parametrize("instance_class", SUPPORTED_GPU_INSTANCE_CLASSES)
@pytest.mark.parametrize("instance_class", sorted(SUPPORTED_GPU_INSTANCE_CLASSES))
def test_default_compiler_config(
time,
name_from_base,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def test_unsupported_cpu_instance(
).fit()


@pytest.mark.parametrize("unsupported_gpu_instance_class", UNSUPPORTED_GPU_INSTANCE_CLASSES)
@pytest.mark.parametrize("unsupported_gpu_instance_class", sorted(UNSUPPORTED_GPU_INSTANCE_CLASSES))
def test_unsupported_gpu_instance(
unsupported_gpu_instance_class,
huggingface_training_compiler_version,
Expand Down Expand Up @@ -315,7 +315,7 @@ def test_unsupported_distribution(
@patch("sagemaker.utils.create_tar_file", MagicMock())
@patch("sagemaker.estimator.name_from_base", return_value=JOB_NAME)
@patch("time.time", return_value=TIME)
@pytest.mark.parametrize("instance_class", SUPPORTED_GPU_INSTANCE_CLASSES)
@pytest.mark.parametrize("instance_class", sorted(SUPPORTED_GPU_INSTANCE_CLASSES))
def test_default_compiler_config(
time,
name_from_base,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def test_unsupported_cpu_instance(cpu_instance_type, pytorch_training_compiler_v
).fit()


@pytest.mark.parametrize("unsupported_gpu_instance_class", UNSUPPORTED_GPU_INSTANCE_CLASSES)
@pytest.mark.parametrize("unsupported_gpu_instance_class", sorted(UNSUPPORTED_GPU_INSTANCE_CLASSES))
def test_unsupported_gpu_instance(
unsupported_gpu_instance_class, pytorch_training_compiler_version
):
Expand Down Expand Up @@ -309,7 +309,7 @@ def test_unsupported_distribution(
@patch("sagemaker.utils.create_tar_file", MagicMock())
@patch("sagemaker.estimator.name_from_base", return_value=JOB_NAME)
@patch("time.time", return_value=TIME)
@pytest.mark.parametrize("instance_class", SUPPORTED_GPU_INSTANCE_CLASSES)
@pytest.mark.parametrize("instance_class", sorted(SUPPORTED_GPU_INSTANCE_CLASSES))
def test_pytorchxla_distribution(
time,
name_from_base,
Expand Down Expand Up @@ -372,7 +372,7 @@ def test_pytorchxla_distribution(
@patch("sagemaker.utils.create_tar_file", MagicMock())
@patch("sagemaker.estimator.name_from_base", return_value=JOB_NAME)
@patch("time.time", return_value=TIME)
@pytest.mark.parametrize("instance_class", SUPPORTED_GPU_INSTANCE_CLASSES)
@pytest.mark.parametrize("instance_class", sorted(SUPPORTED_GPU_INSTANCE_CLASSES))
def test_default_compiler_config(
time,
name_from_base,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ def test_cpu_instance(
compiler_config=TrainingCompilerConfig(),
).fit()

@pytest.mark.parametrize("unsupported_gpu_instance_class", UNSUPPORTED_GPU_INSTANCE_CLASSES)
@pytest.mark.parametrize(
"unsupported_gpu_instance_class", sorted(UNSUPPORTED_GPU_INSTANCE_CLASSES)
)
def test_gpu_instance(
self,
unsupported_gpu_instance_class,
Expand Down Expand Up @@ -254,7 +256,7 @@ def test_python_2(self, tensorflow_training_version):
@patch("sagemaker.estimator.name_from_base", return_value=JOB_NAME)
@patch("time.time", return_value=TIME)
class TestTrainingCompilerConfig:
@pytest.mark.parametrize("instance_class", SUPPORTED_GPU_INSTANCE_CLASSES)
@pytest.mark.parametrize("instance_class", sorted(SUPPORTED_GPU_INSTANCE_CLASSES))
def test_default(
self,
time,
Expand Down Expand Up @@ -308,7 +310,7 @@ def test_default(
actual_train_args == expected_train_args
), f"{json.dumps(actual_train_args, indent=2)} != {json.dumps(expected_train_args, indent=2)}"

@pytest.mark.parametrize("instance_class", SUPPORTED_GPU_INSTANCE_CLASSES)
@pytest.mark.parametrize("instance_class", sorted(SUPPORTED_GPU_INSTANCE_CLASSES))
def test_byoc(
self,
time,
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/sagemaker/workflow/test_training_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@
Join(on="/", values=["s3://my-bucket", "my-input"]),
]

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


@pytest.fixture
def training_input():
Expand Down Expand Up @@ -454,6 +456,7 @@ def test_training_step_estimator_with_param_code_input(
assert step_def == step_def2


@pytest.mark.skip(reason="incompatible with pytest-xdist")
@pytest.mark.parametrize("estimator", ESTIMATOR_LISTS)
@pytest.mark.parametrize("training_input", INPUT_PARAM_LISTS)
@pytest.mark.parametrize(
Expand Down Expand Up @@ -523,6 +526,7 @@ def test_training_step_with_framework_estimator(
assert step_def == step_def2


@pytest.mark.skip(reason="incompatible with pytest-xdist")
@patch("sagemaker.workflow.utilities._pipeline_config", MOCKED_PIPELINE_CONFIG)
@pytest.mark.parametrize("estimator", ESTIMATOR_LISTS_LOCAL_CODE)
@pytest.mark.parametrize("training_input", INPUT_PARAM_LISTS)
Expand Down