2020import os
2121import pathlib
2222import shutil
23+ import warnings
2324
2425import nox
2526
26-
2727BLACK_VERSION = "black==22.3.0"
2828BLACK_PATHS = ["docs" , "google" , "tests" , "noxfile.py" , "setup.py" ]
2929
3030DEFAULT_PYTHON_VERSION = "3.8"
31- SYSTEM_TEST_PYTHON_VERSIONS = [ "3.8" ]
31+
3232UNIT_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 = {}
3357
3458CURRENT_DIRECTORY = pathlib .Path (__file__ ).parent .absolute ()
3559
@@ -93,23 +117,41 @@ def lint_setup_py(session):
93117 session .run ("python" , "setup.py" , "check" , "--restructuredtext" , "--strict" )
94118
95119
120+ def install_unittest_dependencies (session , * constraints ):
121+ standard_deps = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_DEPENDENCIES
122+ session .install (* standard_deps , * constraints )
123+
124+ if UNIT_TEST_EXTERNAL_DEPENDENCIES :
125+ warnings .warn (
126+ "'unit_test_external_dependencies' is deprecated. Instead, please "
127+ "use 'unit_test_dependencies' or 'unit_test_local_dependencies'." ,
128+ DeprecationWarning ,
129+ )
130+ session .install (* UNIT_TEST_EXTERNAL_DEPENDENCIES , * constraints )
131+
132+ if UNIT_TEST_LOCAL_DEPENDENCIES :
133+ session .install (* UNIT_TEST_LOCAL_DEPENDENCIES , * constraints )
134+
135+ if UNIT_TEST_EXTRAS_BY_PYTHON :
136+ extras = UNIT_TEST_EXTRAS_BY_PYTHON .get (session .python , [])
137+ elif UNIT_TEST_EXTRAS :
138+ extras = UNIT_TEST_EXTRAS
139+ else :
140+ extras = []
141+
142+ if extras :
143+ session .install ("-e" , f".[{ ',' .join (extras )} ]" , * constraints )
144+ else :
145+ session .install ("-e" , "." , * constraints )
146+
147+
96148def default (session ):
97149 # Install all test dependencies, then install this package in-place.
98150
99151 constraints_path = str (
100152 CURRENT_DIRECTORY / "testing" / f"constraints-{ session .python } .txt"
101153 )
102- session .install (
103- "mock" ,
104- "asyncmock" ,
105- "pytest" ,
106- "pytest-cov" ,
107- "pytest-asyncio" ,
108- "-c" ,
109- constraints_path ,
110- )
111-
112- session .install ("-e" , "." , "-c" , constraints_path )
154+ install_unittest_dependencies (session , "-c" , constraints_path )
113155
114156 # Run py.test against the unit tests.
115157 session .run (
@@ -133,6 +175,35 @@ def unit(session):
133175 default (session )
134176
135177
178+ def install_systemtest_dependencies (session , * constraints ):
179+
180+ # Use pre-release gRPC for system tests.
181+ session .install ("--pre" , "grpcio" )
182+
183+ session .install (* SYSTEM_TEST_STANDARD_DEPENDENCIES , * constraints )
184+
185+ if SYSTEM_TEST_EXTERNAL_DEPENDENCIES :
186+ session .install (* SYSTEM_TEST_EXTERNAL_DEPENDENCIES , * constraints )
187+
188+ if SYSTEM_TEST_LOCAL_DEPENDENCIES :
189+ session .install ("-e" , * SYSTEM_TEST_LOCAL_DEPENDENCIES , * constraints )
190+
191+ if SYSTEM_TEST_DEPENDENCIES :
192+ session .install ("-e" , * SYSTEM_TEST_DEPENDENCIES , * constraints )
193+
194+ if SYSTEM_TEST_EXTRAS_BY_PYTHON :
195+ extras = SYSTEM_TEST_EXTRAS_BY_PYTHON .get (session .python , [])
196+ elif SYSTEM_TEST_EXTRAS :
197+ extras = SYSTEM_TEST_EXTRAS
198+ else :
199+ extras = []
200+
201+ if extras :
202+ session .install ("-e" , f".[{ ',' .join (extras )} ]" , * constraints )
203+ else :
204+ session .install ("-e" , "." , * constraints )
205+
206+
136207@nox .session (python = SYSTEM_TEST_PYTHON_VERSIONS )
137208@nox .parametrize ("disable_grpc" , [False , True ])
138209def system (session , disable_grpc ):
@@ -156,13 +227,7 @@ def system(session, disable_grpc):
156227 if not system_test_exists and not system_test_folder_exists :
157228 session .skip ("System tests were not found" )
158229
159- # Use pre-release gRPC for system tests.
160- session .install ("--pre" , "grpcio" )
161-
162- # Install all test dependencies, then install this package into the
163- # virtualenv's dist-packages.
164- session .install ("mock" , "pytest" , "google-cloud-testutils" , "-c" , constraints_path )
165- session .install ("-e" , "." , "-c" , constraints_path )
230+ install_systemtest_dependencies (session , "-c" , constraints_path )
166231
167232 env = {}
168233 if disable_grpc :
0 commit comments