55from datetime import datetime
66from unittest .mock import patch
77
8- import boto3
98import numpy as np
109import pandas as pd
10+ import pytest
1111from matplotlib import pyplot
12- from moto import mock_s3
1312
1413from gokart .file_processor import _ChunkedLargeFileReader
1514from 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
1824def _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
174181class 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