-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix tests with incorrect region-skipping code #537
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
Changes from all commits
15ef3c5
0be0147
f58f0a9
07ec016
80159eb
b3bfd66
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,21 +13,21 @@ | |
from __future__ import absolute_import | ||
|
||
import json | ||
import os | ||
|
||
import boto3 | ||
import pytest | ||
from botocore.config import Config | ||
|
||
from sagemaker import Session | ||
from sagemaker.local import LocalSession | ||
from sagemaker.chainer import Chainer | ||
from sagemaker.local import LocalSession | ||
from sagemaker.mxnet import MXNet | ||
from sagemaker.rl import RLEstimator | ||
from sagemaker.pytorch.defaults import PYTORCH_VERSION | ||
from sagemaker.rl import RLEstimator | ||
from sagemaker.sklearn.defaults import SKLEARN_VERSION | ||
from sagemaker.tensorflow.defaults import TF_VERSION | ||
|
||
|
||
DEFAULT_REGION = 'us-west-2' | ||
|
||
|
||
|
@@ -38,12 +38,23 @@ def pytest_addoption(parser): | |
parser.addoption('--chainer-full-version', action='store', default=Chainer.LATEST_VERSION) | ||
parser.addoption('--mxnet-full-version', action='store', default=MXNet.LATEST_VERSION) | ||
parser.addoption('--pytorch-full-version', action='store', default=PYTORCH_VERSION) | ||
parser.addoption('--rl-coach-full-version', action='store', default=RLEstimator.COACH_LATEST_VERSION) | ||
parser.addoption('--rl-ray-full-version', action='store', default=RLEstimator.RAY_LATEST_VERSION) | ||
parser.addoption('--rl-coach-full-version', action='store', | ||
default=RLEstimator.COACH_LATEST_VERSION) | ||
parser.addoption('--rl-ray-full-version', action='store', | ||
default=RLEstimator.RAY_LATEST_VERSION) | ||
parser.addoption('--sklearn-full-version', action='store', default=SKLEARN_VERSION) | ||
parser.addoption('--tf-full-version', action='store', default=TF_VERSION) | ||
|
||
|
||
def pytest_configure(config): | ||
bc = config.getoption('--boto-config') | ||
parsed = json.loads(bc) if bc else {} | ||
region = parsed.get('region_name', boto3.session.Session().region_name) | ||
|
||
if region: | ||
os.environ['TEST_AWS_REGION_NAME'] = region | ||
|
||
|
||
@pytest.fixture(scope='session') | ||
def sagemaker_client_config(request): | ||
config = request.config.getoption('--sagemaker-client-config') | ||
|
@@ -64,10 +75,13 @@ def boto_config(request): | |
|
||
@pytest.fixture(scope='session') | ||
def sagemaker_session(sagemaker_client_config, sagemaker_runtime_config, boto_config): | ||
boto_session = boto3.Session(**boto_config) if boto_config else boto3.Session(region_name=DEFAULT_REGION) | ||
boto_session = boto3.Session(**boto_config) if boto_config else boto3.Session( | ||
region_name=DEFAULT_REGION) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not in scope of this PR, but seeing this and scanning through conftest.py makes me think we should make a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agree, there should be another PR for this. |
||
sagemaker_client_config.setdefault('config', Config(retries=dict(max_attempts=10))) | ||
sagemaker_client = boto_session.client('sagemaker', **sagemaker_client_config) if sagemaker_client_config else None | ||
runtime_client = (boto_session.client('sagemaker-runtime', **sagemaker_runtime_config) if sagemaker_runtime_config | ||
sagemaker_client = boto_session.client('sagemaker', | ||
**sagemaker_client_config) if sagemaker_client_config else None | ||
runtime_client = (boto_session.client('sagemaker-runtime', | ||
**sagemaker_runtime_config) if sagemaker_runtime_config | ||
else None) | ||
|
||
return Session(boto_session=boto_session, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this go in
conftest.py
or__init__.py
instead of individual test files or is there a reason it's specific to this file?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, it must be in this file for pytest to call it (and set the env var) at the correct time. stuff in init.py doesn't have access to the pytest config (part of the original problem).