20
20
import os
21
21
import pathlib
22
22
import shutil
23
+ import warnings
23
24
24
25
import nox
25
26
26
-
27
27
BLACK_VERSION = "black==22.3.0"
28
28
BLACK_PATHS = ["docs" , "google" , "tests" , "noxfile.py" , "setup.py" ]
29
29
30
30
DEFAULT_PYTHON_VERSION = "3.8"
31
- SYSTEM_TEST_PYTHON_VERSIONS = [ "3.8" ]
31
+
32
32
UNIT_TEST_PYTHON_VERSIONS = ["3.6" , "3.7" , "3.8" , "3.9" , "3.10" ]
33
+ UNIT_TEST_STANDARD_DEPENDENCIES = [
34
+ "mock" ,
35
+ "asyncmock" ,
36
+ "pytest" ,
37
+ "pytest-cov" ,
38
+ "pytest-asyncio" ,
39
+ ]
40
+ UNIT_TEST_EXTERNAL_DEPENDENCIES = []
41
+ UNIT_TEST_LOCAL_DEPENDENCIES = []
42
+ UNIT_TEST_DEPENDENCIES = []
43
+ UNIT_TEST_EXTRAS = []
44
+ UNIT_TEST_EXTRAS_BY_PYTHON = {}
45
+
46
+ SYSTEM_TEST_PYTHON_VERSIONS = ["3.8" ]
47
+ SYSTEM_TEST_STANDARD_DEPENDENCIES = [
48
+ "mock" ,
49
+ "pytest" ,
50
+ "google-cloud-testutils" ,
51
+ ]
52
+ SYSTEM_TEST_EXTERNAL_DEPENDENCIES = []
53
+ SYSTEM_TEST_LOCAL_DEPENDENCIES = []
54
+ SYSTEM_TEST_DEPENDENCIES = []
55
+ SYSTEM_TEST_EXTRAS = []
56
+ SYSTEM_TEST_EXTRAS_BY_PYTHON = {}
33
57
34
58
CURRENT_DIRECTORY = pathlib .Path (__file__ ).parent .absolute ()
35
59
@@ -81,23 +105,41 @@ def lint_setup_py(session):
81
105
session .run ("python" , "setup.py" , "check" , "--restructuredtext" , "--strict" )
82
106
83
107
108
+ def install_unittest_dependencies (session , * constraints ):
109
+ standard_deps = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_DEPENDENCIES
110
+ session .install (* standard_deps , * constraints )
111
+
112
+ if UNIT_TEST_EXTERNAL_DEPENDENCIES :
113
+ warnings .warn (
114
+ "'unit_test_external_dependencies' is deprecated. Instead, please "
115
+ "use 'unit_test_dependencies' or 'unit_test_local_dependencies'." ,
116
+ DeprecationWarning ,
117
+ )
118
+ session .install (* UNIT_TEST_EXTERNAL_DEPENDENCIES , * constraints )
119
+
120
+ if UNIT_TEST_LOCAL_DEPENDENCIES :
121
+ session .install (* UNIT_TEST_LOCAL_DEPENDENCIES , * constraints )
122
+
123
+ if UNIT_TEST_EXTRAS_BY_PYTHON :
124
+ extras = UNIT_TEST_EXTRAS_BY_PYTHON .get (session .python , [])
125
+ elif UNIT_TEST_EXTRAS :
126
+ extras = UNIT_TEST_EXTRAS
127
+ else :
128
+ extras = []
129
+
130
+ if extras :
131
+ session .install ("-e" , f".[{ ',' .join (extras )} ]" , * constraints )
132
+ else :
133
+ session .install ("-e" , "." , * constraints )
134
+
135
+
84
136
def default (session ):
85
137
# Install all test dependencies, then install this package in-place.
86
138
87
139
constraints_path = str (
88
140
CURRENT_DIRECTORY / "testing" / f"constraints-{ session .python } .txt"
89
141
)
90
- session .install (
91
- "mock" ,
92
- "asyncmock" ,
93
- "pytest" ,
94
- "pytest-cov" ,
95
- "pytest-asyncio" ,
96
- "-c" ,
97
- constraints_path ,
98
- )
99
-
100
- session .install ("-e" , "." , "-c" , constraints_path )
142
+ install_unittest_dependencies (session , "-c" , constraints_path )
101
143
102
144
# Run py.test against the unit tests.
103
145
session .run (
@@ -121,6 +163,35 @@ def unit(session):
121
163
default (session )
122
164
123
165
166
+ def install_systemtest_dependencies (session , * constraints ):
167
+
168
+ # Use pre-release gRPC for system tests.
169
+ session .install ("--pre" , "grpcio" )
170
+
171
+ session .install (* SYSTEM_TEST_STANDARD_DEPENDENCIES , * constraints )
172
+
173
+ if SYSTEM_TEST_EXTERNAL_DEPENDENCIES :
174
+ session .install (* SYSTEM_TEST_EXTERNAL_DEPENDENCIES , * constraints )
175
+
176
+ if SYSTEM_TEST_LOCAL_DEPENDENCIES :
177
+ session .install ("-e" , * SYSTEM_TEST_LOCAL_DEPENDENCIES , * constraints )
178
+
179
+ if SYSTEM_TEST_DEPENDENCIES :
180
+ session .install ("-e" , * SYSTEM_TEST_DEPENDENCIES , * constraints )
181
+
182
+ if SYSTEM_TEST_EXTRAS_BY_PYTHON :
183
+ extras = SYSTEM_TEST_EXTRAS_BY_PYTHON .get (session .python , [])
184
+ elif SYSTEM_TEST_EXTRAS :
185
+ extras = SYSTEM_TEST_EXTRAS
186
+ else :
187
+ extras = []
188
+
189
+ if extras :
190
+ session .install ("-e" , f".[{ ',' .join (extras )} ]" , * constraints )
191
+ else :
192
+ session .install ("-e" , "." , * constraints )
193
+
194
+
124
195
@nox .session (python = SYSTEM_TEST_PYTHON_VERSIONS )
125
196
def system (session ):
126
197
"""Run the system test suite."""
@@ -143,13 +214,7 @@ def system(session):
143
214
if not system_test_exists and not system_test_folder_exists :
144
215
session .skip ("System tests were not found" )
145
216
146
- # Use pre-release gRPC for system tests.
147
- session .install ("--pre" , "grpcio" )
148
-
149
- # Install all test dependencies, then install this package into the
150
- # virtualenv's dist-packages.
151
- session .install ("mock" , "pytest" , "google-cloud-testutils" , "-c" , constraints_path )
152
- session .install ("-e" , "." , "-c" , constraints_path )
217
+ install_systemtest_dependencies (session , "-c" , constraints_path )
153
218
154
219
# Run py.test against the system tests.
155
220
if system_test_exists :
0 commit comments