Skip to content

Commit e553dae

Browse files
committed
mark tests
1 parent fe7b999 commit e553dae

5 files changed

Lines changed: 64 additions & 13 deletions

File tree

test/helpers.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
def safe_mock_s3(func):
2+
"""
3+
Annotations will be evaluated even if `pytes -m "not s3"` is specified. So
4+
```
5+
@pytest.mark.s3
6+
class TestS3(unittest.TestCase):
7+
@mock_s3
8+
def test_foo():
9+
```
10+
will raise an error if moto is not installed.
11+
This decorator is used to avoid this error.
12+
"""
13+
14+
# try:
15+
# from moto import mock_s3
16+
# return mock_s3(func)
17+
# except ImportError:
18+
# return func
19+
def wrapper(*args, **kwargs):
20+
from moto import mock_s3
21+
with mock_s3():
22+
return func(*args, **kwargs)
23+
24+
return wrapper

test/test_gcs_config.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22
import unittest
33
from unittest.mock import MagicMock, patch
44

5-
from gokart.gcs_config import GCSConfig
5+
import pytest
66

7+
try:
8+
from gokart.gcs_config import GCSConfig
9+
except ImportError:
10+
pass
711

12+
13+
@pytest.mark.gcs
814
class TestGCSConfig(unittest.TestCase):
915

1016
def test_get_gcs_client_without_gcs_credential_name(self):

test/test_s3_config.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
import unittest
22

3-
from gokart.s3_config import S3Config
3+
import pytest
44

5+
try:
6+
from gokart.s3_config import S3Config
7+
except ImportError:
8+
pass
59

10+
11+
@pytest.mark.s3
612
class TestS3Config(unittest.TestCase):
713

814
def test_get_same_s3_client(self):

test/test_s3_zip_client.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,29 @@
22
import shutil
33
import unittest
44

5-
import boto3
6-
from moto import mock_s3
5+
import pytest
76

8-
from gokart.s3_zip_client import S3ZipClient
7+
from .helpers import safe_mock_s3
8+
9+
try:
10+
import boto3
11+
12+
from gokart.s3_zip_client import S3ZipClient
13+
except ImportError:
14+
pass
915

1016

1117
def _get_temporary_directory():
1218
return os.path.abspath(os.path.join(os.path.dirname(__name__), 'temporary'))
1319

1420

21+
@pytest.mark.s3
1522
class TestS3ZipClient(unittest.TestCase):
1623

1724
def tearDown(self):
1825
shutil.rmtree(_get_temporary_directory(), ignore_errors=True)
1926

20-
@mock_s3
27+
@safe_mock_s3
2128
def test_make_archive(self):
2229
conn = boto3.resource('s3', region_name='us-east-1')
2330
conn.create_bucket(Bucket='test')
@@ -34,7 +41,7 @@ def test_make_archive(self):
3441
os.makedirs(temporary_directory, exist_ok=True)
3542
zip_client.make_archive()
3643

37-
@mock_s3
44+
@safe_mock_s3
3845
def test_unpack_archive(self):
3946
conn = boto3.resource('s3', region_name='us-east-1')
4047
conn.create_bucket(Bucket='test')

test/test_target.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,21 @@
55
from datetime import datetime
66
from unittest.mock import patch
77

8-
import boto3
98
import numpy as np
109
import pandas as pd
10+
import pytest
1111
from matplotlib import pyplot
12-
from moto import mock_s3
1312

1413
from gokart.file_processor import _ChunkedLargeFileReader
1514
from gokart.target import make_model_target, make_target
1615

16+
from .helpers import safe_mock_s3
17+
18+
try:
19+
import boto3
20+
except:
21+
pass
22+
1723

1824
def _get_temporary_directory():
1925
return os.path.abspath(os.path.join(os.path.dirname(__name__), 'temporary'))
@@ -171,9 +177,10 @@ def test_dump_without_lock(self):
171177
wrap_with_lock_mock.assert_not_called()
172178

173179

180+
@pytest.mark.s3
174181
class S3TargetTest(unittest.TestCase):
175182

176-
@mock_s3
183+
@safe_mock_s3
177184
def test_save_on_s3(self):
178185
conn = boto3.resource('s3', region_name='us-east-1')
179186
conn.create_bucket(Bucket='test')
@@ -187,7 +194,7 @@ def test_save_on_s3(self):
187194

188195
self.assertEqual(loaded, obj)
189196

190-
@mock_s3
197+
@safe_mock_s3
191198
def test_last_modified_time(self):
192199
conn = boto3.resource('s3', region_name='us-east-1')
193200
conn.create_bucket(Bucket='test')
@@ -200,7 +207,7 @@ def test_last_modified_time(self):
200207
t = target.last_modification_time()
201208
self.assertIsInstance(t, datetime)
202209

203-
@mock_s3
210+
@safe_mock_s3
204211
def test_last_modified_time_without_file(self):
205212
conn = boto3.resource('s3', region_name='us-east-1')
206213
conn.create_bucket(Bucket='test')
@@ -238,7 +245,8 @@ def test_model_target_on_local(self):
238245

239246
self.assertEqual(loaded, obj)
240247

241-
@mock_s3
248+
@pytest.mark.s3
249+
@safe_mock_s3
242250
def test_model_target_on_s3(self):
243251
conn = boto3.resource('s3', region_name='us-east-1')
244252
conn.create_bucket(Bucket='test')

0 commit comments

Comments
 (0)