Skip to content
This repository was archived by the owner on Sep 13, 2023. It is now read-only.

Commit 2b63b34

Browse files
authored
Add more test decorators (#669)
Not sure if this is accepted but some tests fail locally when credentials/env variables are not set. I see that there are already decorators for this purpose, this PR extends those decorators.
1 parent bd230a2 commit 2b63b34

File tree

9 files changed

+26
-5
lines changed

9 files changed

+26
-5
lines changed

tests/api/test_commands.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from mlem.core.model import ModelIO
1818
from mlem.core.objects import MAIN_PROCESSOR_NAME, MlemLink, MlemModel
1919
from mlem.runtime.client import HTTPClient
20-
from tests.conftest import MLEM_TEST_REPO, long
20+
from tests.conftest import MLEM_TEST_REPO, long, need_aws_auth
2121

2222
IMPORT_MODEL_FILENAME = "mymodel"
2323

@@ -120,6 +120,7 @@ def test_init(tmpdir):
120120

121121

122122
@long
123+
@need_aws_auth
123124
def test_init_remote(s3_tmp_path, s3_storage_fs):
124125
path = s3_tmp_path("init")
125126
init(path)
@@ -205,6 +206,7 @@ def test_import_model_pickle__no_copy_in_mlem_project(
205206

206207

207208
@long
209+
@need_aws_auth
208210
def test_import_model_pickle_remote(
209211
s3_tmp_path, s3_storage_fs, write_model_pickle, tmpdir, train
210212
):
@@ -223,6 +225,7 @@ def test_import_model_pickle_remote(
223225

224226

225227
@long
228+
@need_aws_auth
226229
def test_import_model_pickle_remote_in_project(
227230
s3_tmp_path, s3_storage_fs, write_model_pickle, train
228231
):

tests/conftest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from pathlib import Path
55
from typing import Any, Callable, Set, Type
66

7+
import boto3
78
import git
89
import numpy as np
910
import pandas as pd
@@ -75,6 +76,11 @@ def _check_github_test_repo_auth():
7576
reason="No ssh credentials for remote repo",
7677
)
7778

79+
need_aws_auth = pytest.mark.skipif(
80+
boto3.Session().get_credentials() is None,
81+
reason="AWS credentials missing",
82+
)
83+
7884

7985
def get_current_test_branch(branch_list: Set[str]):
8086
try:

tests/contrib/test_bitbucket.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
def fs_no_auth():
2020
username = os.environ.get("BITBUCKET_USERNAME", None)
2121
try:
22-
del os.environ["BITBUCKET_USERNAME"]
22+
os.environ.pop("BITBUCKET_USERNAME", None)
2323
yield BitBucketFileSystem(MLEM_TEST_REPO_PROJECT)
2424
finally:
2525
if username:

tests/contrib/test_heroku.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ def no_heroku_env():
217217
HEROKU_CONFIG.API_KEY = conf_tmp
218218

219219

220+
@heroku
220221
def test_suggest_login(no_heroku_env, heroku_app_name, heroku_env):
221222
with pytest.raises(
222223
DeploymentError,

tests/contrib/test_pandas.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
from mlem.core.model import Signature
4747
from mlem.core.objects import MlemData
4848
from mlem.utils.module import get_object_requirements
49-
from tests.conftest import data_write_read_check, long
49+
from tests.conftest import data_write_read_check, long, need_aws_auth
5050

5151
PD_DATA_FRAME = pd.DataFrame(
5252
[
@@ -527,6 +527,7 @@ def test_import_data_stata(tmpdir, data):
527527

528528

529529
@long
530+
@need_aws_auth
530531
def test_import_data_csv_remote(s3_tmp_path, s3_storage_fs, write_csv):
531532
project_path = s3_tmp_path("test_csv_import")
532533
path = posixpath.join(project_path, "data.csv")

tests/core/test_artifacts.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
LocalArtifact,
1111
LocalStorage,
1212
)
13-
from tests.conftest import long, resource_path
13+
from tests.conftest import long, need_aws_auth, resource_path
1414

1515

1616
@long
17+
@need_aws_auth
1718
def test_fsspec_backend_s3_upload(tmpdir, s3_tmp_path, s3_storage):
1819
target = os.path.basename(s3_tmp_path("upload"))
1920
resource = resource_path(__file__, "file.txt")
@@ -30,6 +31,7 @@ def test_fsspec_backend_s3_upload(tmpdir, s3_tmp_path, s3_storage):
3031

3132

3233
@long
34+
@need_aws_auth
3335
def test_fsspec_backend_s3_open(s3_tmp_path, s3_storage):
3436
target = os.path.basename(s3_tmp_path("open"))
3537
with s3_storage.open(target) as (f, artifact):

tests/core/test_metadata.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
MLEM_TEST_REPO_NAME,
3434
MLEM_TEST_REPO_ORG,
3535
long,
36+
need_aws_auth,
3637
need_test_repo_auth,
3738
need_test_repo_ssh_auth,
3839
)
@@ -96,6 +97,7 @@ def test_model_loading(model_path):
9697

9798
@long
9899
@need_test_repo_ssh_auth
100+
@need_aws_auth
99101
def test_model_loading_remote_dvc(current_test_branch):
100102
model = load(
101103
f"{MLEM_TEST_REPO}/dvc_pipeline/data/model",
@@ -170,6 +172,7 @@ def test_load_link_with_fsspec_path(current_test_branch):
170172

171173

172174
@long
175+
@need_aws_auth
173176
def test_saving_to_s3(model, s3_storage_fs, s3_tmp_path):
174177
path = s3_tmp_path("model_save")
175178
init(path)
@@ -182,6 +185,7 @@ def test_saving_to_s3(model, s3_storage_fs, s3_tmp_path):
182185

183186

184187
@long
188+
@need_aws_auth
185189
def test_loading_from_s3(model, s3_storage_fs, s3_tmp_path):
186190
path = s3_tmp_path("model_load")
187191
init(path)
@@ -252,6 +256,7 @@ def test_ls_remote(current_test_branch):
252256

253257

254258
@long
259+
@need_aws_auth
255260
def test_ls_remote_s3(s3_tmp_path):
256261
path = s3_tmp_path("ls_remote_s3")
257262
init(path)

tests/core/test_objects.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
MLEM_TEST_REPO,
3333
flaky,
3434
long,
35+
need_aws_auth,
3536
need_test_repo_auth,
3637
need_test_repo_ssh_auth,
3738
)
@@ -194,6 +195,7 @@ def test_model_cloning_to_project(model_single_path, mlem_project):
194195

195196

196197
@long
198+
@need_aws_auth
197199
def test_model_cloning_to_remote(model_path, s3_tmp_path, s3_storage_fs):
198200
model = load_meta(model_path)
199201
path = s3_tmp_path("model_cloning_to_remote")

tests/test_config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from mlem.contrib.fastapi import FastAPIServer
66
from mlem.core.artifacts import FSSpecStorage, LocalStorage
77
from mlem.core.meta_io import get_fs
8-
from tests.conftest import long
8+
from tests.conftest import long, need_aws_auth
99

1010

1111
def test_loading_storage(set_mlem_project_root):
@@ -21,6 +21,7 @@ def test_loading_empty(set_mlem_project_root):
2121
assert isinstance(config.storage, LocalStorage)
2222

2323

24+
@need_aws_auth
2425
@long
2526
def test_loading_remote(s3_tmp_path, s3_storage_fs):
2627
project = s3_tmp_path("remote_conf")

0 commit comments

Comments
 (0)