1
- import os
2
1
import shlex
3
2
import subprocess
4
3
import time
13
12
)
14
13
import pandas .util ._test_decorators as td
15
14
16
- import pandas ._testing as tm
17
-
18
15
import pandas .io .common as icom
19
16
from pandas .io .parsers import read_csv
20
17
@@ -58,7 +55,13 @@ def s3so(worker_id):
58
55
59
56
60
57
@pytest .fixture (scope = "session" )
61
- def s3_base (worker_id ):
58
+ def monkeysession ():
59
+ with pytest .MonkeyPatch .context () as mp :
60
+ yield mp
61
+
62
+
63
+ @pytest .fixture (scope = "session" )
64
+ def s3_base (worker_id , monkeysession ):
62
65
"""
63
66
Fixture for mocking S3 interaction.
64
67
@@ -68,56 +71,55 @@ def s3_base(worker_id):
68
71
pytest .importorskip ("s3fs" )
69
72
pytest .importorskip ("boto3" )
70
73
71
- with tm .ensure_safe_environment_variables ():
72
- # temporary workaround as moto fails for botocore >= 1.11 otherwise,
73
- # see https://github.com/spulec/moto/issues/1924 & 1952
74
- os .environ .setdefault ("AWS_ACCESS_KEY_ID" , "foobar_key" )
75
- os .environ .setdefault ("AWS_SECRET_ACCESS_KEY" , "foobar_secret" )
76
- if is_ci_environment ():
77
- if is_platform_arm () or is_platform_mac () or is_platform_windows ():
78
- # NOT RUN on Windows/macOS/ARM, only Ubuntu
79
- # - subprocess in CI can cause timeouts
80
- # - GitHub Actions do not support
81
- # container services for the above OSs
82
- # - CircleCI will probably hit the Docker rate pull limit
83
- pytest .skip (
84
- "S3 tests do not have a corresponding service in "
85
- "Windows, macOS or ARM platforms"
86
- )
87
- else :
88
- yield "http://localhost:5000"
74
+ # temporary workaround as moto fails for botocore >= 1.11 otherwise,
75
+ # see https://github.com/spulec/moto/issues/1924 & 1952
76
+ monkeysession .setenv ("AWS_ACCESS_KEY_ID" , "foobar_key" )
77
+ monkeysession .setenv ("AWS_SECRET_ACCESS_KEY" , "foobar_secret" )
78
+ if is_ci_environment ():
79
+ if is_platform_arm () or is_platform_mac () or is_platform_windows ():
80
+ # NOT RUN on Windows/macOS/ARM, only Ubuntu
81
+ # - subprocess in CI can cause timeouts
82
+ # - GitHub Actions do not support
83
+ # container services for the above OSs
84
+ # - CircleCI will probably hit the Docker rate pull limit
85
+ pytest .skip (
86
+ "S3 tests do not have a corresponding service in "
87
+ "Windows, macOS or ARM platforms"
88
+ )
89
89
else :
90
- requests = pytest .importorskip ("requests" )
91
- pytest .importorskip ("moto" , minversion = "1.3.14" )
92
- pytest .importorskip ("flask" ) # server mode needs flask too
93
-
94
- # Launching moto in server mode, i.e., as a separate process
95
- # with an S3 endpoint on localhost
96
-
97
- worker_id = "5" if worker_id == "master" else worker_id .lstrip ("gw" )
98
- endpoint_port = f"555{ worker_id } "
99
- endpoint_uri = f"http://127.0.0.1:{ endpoint_port } /"
100
-
101
- # pipe to null to avoid logging in terminal
102
- with subprocess .Popen (
103
- shlex .split (f"moto_server s3 -p { endpoint_port } " ),
104
- stdout = subprocess .DEVNULL ,
105
- stderr = subprocess .DEVNULL ,
106
- ) as proc :
107
- timeout = 5
108
- while timeout > 0 :
109
- try :
110
- # OK to go once server is accepting connections
111
- r = requests .get (endpoint_uri )
112
- if r .ok :
113
- break
114
- except Exception :
115
- pass
116
- timeout -= 0.1
117
- time .sleep (0.1 )
118
- yield endpoint_uri
119
-
120
- proc .terminate ()
90
+ yield "http://localhost:5000"
91
+ else :
92
+ requests = pytest .importorskip ("requests" )
93
+ pytest .importorskip ("moto" , minversion = "1.3.14" )
94
+ pytest .importorskip ("flask" ) # server mode needs flask too
95
+
96
+ # Launching moto in server mode, i.e., as a separate process
97
+ # with an S3 endpoint on localhost
98
+
99
+ worker_id = "5" if worker_id == "master" else worker_id .lstrip ("gw" )
100
+ endpoint_port = f"555{ worker_id } "
101
+ endpoint_uri = f"http://127.0.0.1:{ endpoint_port } /"
102
+
103
+ # pipe to null to avoid logging in terminal
104
+ with subprocess .Popen (
105
+ shlex .split (f"moto_server s3 -p { endpoint_port } " ),
106
+ stdout = subprocess .DEVNULL ,
107
+ stderr = subprocess .DEVNULL ,
108
+ ) as proc :
109
+ timeout = 5
110
+ while timeout > 0 :
111
+ try :
112
+ # OK to go once server is accepting connections
113
+ r = requests .get (endpoint_uri )
114
+ if r .ok :
115
+ break
116
+ except Exception :
117
+ pass
118
+ timeout -= 0.1
119
+ time .sleep (0.1 )
120
+ yield endpoint_uri
121
+
122
+ proc .terminate ()
121
123
122
124
123
125
@pytest .fixture
0 commit comments