Skip to content

Commit aa273c9

Browse files
committed
infra: address warnings about pytest custom marks, error message checking, and yaml loading
1 parent 0061be9 commit aa273c9

File tree

10 files changed

+31
-30
lines changed

10 files changed

+31
-30
lines changed

tests/integ/test_chainer_train.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ def test_training_with_additional_hyperparameters(sagemaker_local_session, chain
6161

6262

6363
@pytest.mark.canary_quick
64-
@pytest.mark.regional_testing
6564
def test_attach_deploy(sagemaker_session, chainer_full_version, cpu_instance_type):
6665
with timeout(minutes=TRAINING_DEFAULT_TIMEOUT_MINUTES):
6766
script_path = os.path.join(DATA_DIR, "chainer_mnist", "mnist.py")

tests/integ/test_inference_pipeline.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@
5151
)
5252

5353

54-
@pytest.mark.continuous_testing
55-
@pytest.mark.regional_testing
5654
def test_inference_pipeline_batch_transform(sagemaker_session, cpu_instance_type):
5755
sparkml_model_data = sagemaker_session.upload_data(
5856
path=os.path.join(SPARKML_DATA_PATH, "mleap_model.tar.gz"),
@@ -94,7 +92,6 @@ def test_inference_pipeline_batch_transform(sagemaker_session, cpu_instance_type
9492

9593

9694
@pytest.mark.canary_quick
97-
@pytest.mark.regional_testing
9895
@pytest.mark.skip(
9996
reason="This test has always failed, but the failure was masked by a bug. "
10097
"This test should be fixed. Details in https://github.com/aws/sagemaker-python-sdk/pull/968"

tests/integ/test_mxnet_train.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ def mxnet_training_job(sagemaker_session, mxnet_full_version, cpu_instance_type)
5656

5757

5858
@pytest.mark.canary_quick
59-
@pytest.mark.regional_testing
6059
def test_attach_deploy(mxnet_training_job, sagemaker_session, cpu_instance_type):
6160
endpoint_name = "test-mxnet-attach-deploy-{}".format(sagemaker_timestamp())
6261

@@ -238,7 +237,6 @@ def test_deploy_model_with_update_non_existing_endpoint(
238237

239238

240239
@pytest.mark.canary_quick
241-
@pytest.mark.regional_testing
242240
@pytest.mark.skipif(
243241
tests.integ.test_region() not in tests.integ.EI_SUPPORTED_REGIONS,
244242
reason="EI isn't supported in that specific region.",

tests/integ/test_neo_mxnet.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ def mxnet_training_job(sagemaker_session, cpu_instance_type):
5555

5656

5757
@pytest.mark.canary_quick
58-
@pytest.mark.regional_testing
5958
def test_attach_deploy(
6059
mxnet_training_job, sagemaker_session, cpu_instance_type, cpu_instance_family
6160
):

tests/integ/test_pytorch_train.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ def fixture_training_job(sagemaker_session, pytorch_full_version, cpu_instance_t
4848

4949

5050
@pytest.mark.canary_quick
51-
@pytest.mark.regional_testing
5251
@pytest.mark.skipif(
5352
PYTHON_VERSION == "py2",
5453
reason="Python 2 is supported by PyTorch {} and lower versions.".format(LATEST_PY2_VERSION),

tests/integ/test_sklearn_train.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ def test_training_with_network_isolation(
101101

102102

103103
@pytest.mark.canary_quick
104-
@pytest.mark.regional_testing
105104
@pytest.mark.skipif(PYTHON_VERSION != "py3", reason="Scikit-learn image supports only python 3.")
106105
@pytest.mark.skip(
107106
reason="This test has always failed, but the failure was masked by a bug. "

tests/integ/test_sparkml_serving.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525

2626
@pytest.mark.canary_quick
27-
@pytest.mark.regional_testing
2827
@pytest.mark.skip(
2928
reason="This test has always failed, but the failure was masked by a bug. "
3029
"This test should be fixed. Details in https://github.com/aws/sagemaker-python-sdk/pull/968"

tests/unit/sagemaker/automl/test_auto_ml.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -273,26 +273,30 @@ def test_auto_ml_invalid_input_data_format(sagemaker_session):
273273
)
274274
inputs = {}
275275

276-
expected_error_msg = "Cannot format input {}. Expecting one of str or list of strings."
277-
with pytest.raises(ValueError, message=expected_error_msg.format(inputs)):
276+
with pytest.raises(ValueError) as excinfo:
278277
AutoMLJob.start_new(auto_ml, inputs)
278+
279+
expected_error_msg = "Cannot format input {}. Expecting a string or a list of strings."
280+
assert expected_error_msg.format(inputs) in str(excinfo.value)
281+
279282
sagemaker_session.auto_ml.assert_not_called()
280283

281284

282285
def test_auto_ml_only_one_of_problem_type_and_job_objective_provided(sagemaker_session):
283-
with pytest.raises(
284-
ValueError,
285-
message="One of problem type and objective metric provided. "
286-
"Either both of them should be provided or none of "
287-
"them should be provided.",
288-
):
286+
with pytest.raises(ValueError) as excinfo:
289287
AutoML(
290288
role=ROLE,
291289
target_attribute_name=TARGET_ATTRIBUTE_NAME,
292290
sagemaker_session=sagemaker_session,
293291
problem_type=PROBLEM_TYPE,
294292
)
295293

294+
message = (
295+
"One of problem type and objective metric provided. Either both of them "
296+
"should be provided or none of them should be provided."
297+
)
298+
assert message in str(excinfo.value)
299+
296300

297301
@patch("sagemaker.automl.automl.AutoMLJob.start_new")
298302
def test_auto_ml_fit_set_logs_to_false(start_new, sagemaker_session, caplog):
@@ -637,15 +641,16 @@ def test_validate_and_update_inference_response():
637641
def test_validate_and_update_inference_response_wrong_input():
638642
cic = copy.copy(CLASSIFICATION_INFERENCE_CONTAINERS)
639643

640-
with pytest.raises(
641-
ValueError,
642-
message="Requested inference output keys [wrong_key, wrong_label] are unsupported. "
643-
"The supported inference keys are [probability, probabilities, predicted_label, labels]",
644-
):
644+
with pytest.raises(ValueError) as excinfo:
645645
AutoML.validate_and_update_inference_response(
646646
inference_containers=cic,
647647
inference_response_keys=["wrong_key", "wrong_label", "probabilities", "probability"],
648648
)
649+
message = (
650+
"Requested inference output keys [wrong_key, wrong_label] are unsupported. "
651+
"The supported inference keys are [probability, probabilities, predicted_label, labels]"
652+
)
653+
assert message in str(excinfo.value)
649654

650655

651656
def test_create_model(sagemaker_session):

tests/unit/test_image.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ def test_train(
370370
assert call_args[i] == v
371371

372372
with open(docker_compose_file, "r") as f:
373-
config = yaml.load(f)
373+
config = yaml.load(f, Loader=yaml.SafeLoader)
374374
assert len(config["services"]) == instance_count
375375
for h in sagemaker_container.hosts:
376376
assert config["services"][h]["image"] == image
@@ -419,7 +419,7 @@ def test_train_with_hyperparameters_without_job_name(
419419
)
420420

421421
with open(docker_compose_file, "r") as f:
422-
config = yaml.load(f)
422+
config = yaml.load(f, Loader=yaml.SafeLoader)
423423
for h in sagemaker_container.hosts:
424424
assert (
425425
"TRAINING_JOB_NAME={}".format(TRAINING_JOB_NAME)
@@ -491,7 +491,7 @@ def test_train_local_code(get_data_source_instance, tmpdir, sagemaker_session):
491491
shared_folder_path = os.path.join(sagemaker_container.container_root, "shared")
492492

493493
with open(docker_compose_file, "r") as f:
494-
config = yaml.load(f)
494+
config = yaml.load(f, Loader=yaml.SafeLoader)
495495
assert len(config["services"]) == instance_count
496496

497497
for h in sagemaker_container.hosts:
@@ -543,7 +543,7 @@ def test_train_local_intermediate_output(get_data_source_instance, tmpdir, sagem
543543
intermediate_folder_path = os.path.join(output_path, "output/intermediate")
544544

545545
with open(docker_compose_file, "r") as f:
546-
config = yaml.load(f)
546+
config = yaml.load(f, Loader=yaml.SafeLoader)
547547
assert len(config["services"]) == instance_count
548548
for h in sagemaker_container.hosts:
549549
assert config["services"][h]["image"] == image
@@ -596,7 +596,7 @@ def test_serve(tmpdir, sagemaker_session):
596596
)
597597

598598
with open(docker_compose_file, "r") as f:
599-
config = yaml.load(f)
599+
config = yaml.load(f, Loader=yaml.SafeLoader)
600600

601601
for h in sagemaker_container.hosts:
602602
assert config["services"][h]["image"] == image
@@ -624,7 +624,7 @@ def test_serve_local_code(tmpdir, sagemaker_session):
624624
)
625625

626626
with open(docker_compose_file, "r") as f:
627-
config = yaml.load(f)
627+
config = yaml.load(f, Loader=yaml.SafeLoader)
628628

629629
for h in sagemaker_container.hosts:
630630
assert config["services"][h]["image"] == image
@@ -657,7 +657,7 @@ def test_serve_local_code_no_env(tmpdir, sagemaker_session):
657657
)
658658

659659
with open(docker_compose_file, "r") as f:
660-
config = yaml.load(f)
660+
config = yaml.load(f, Loader=yaml.SafeLoader)
661661

662662
for h in sagemaker_container.hosts:
663663
assert config["services"][h]["image"] == image

tox.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ ignore-path=.tox,src/sagemaker.egg-info
5151
# TODO: fix files before enabling max-line-length (D001)
5252
ignore=D001
5353

54+
[pytest]
55+
markers =
56+
canary_quick
57+
cron
58+
local_mode
59+
5460
[testenv]
5561
passenv =
5662
AWS_ACCESS_KEY_ID

0 commit comments

Comments
 (0)