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+ "flask" ,
42+ "webob" ,
43+ "django" ,
44+ ]
45+ UNIT_TEST_LOCAL_DEPENDENCIES = []
46+ UNIT_TEST_DEPENDENCIES = []
47+ UNIT_TEST_EXTRAS = []
48+ UNIT_TEST_EXTRAS_BY_PYTHON = {}
49+
50+ SYSTEM_TEST_PYTHON_VERSIONS = ["3.8" ]
51+ SYSTEM_TEST_STANDARD_DEPENDENCIES = [
52+ "mock" ,
53+ "pytest" ,
54+ "google-cloud-testutils" ,
55+ ]
56+ SYSTEM_TEST_EXTERNAL_DEPENDENCIES = [
57+ "google-cloud-bigquery" ,
58+ "google-cloud-pubsub" ,
59+ "google-cloud-storage" ,
60+ "google-cloud-testutils" ,
61+ ]
62+ SYSTEM_TEST_LOCAL_DEPENDENCIES = []
63+ SYSTEM_TEST_DEPENDENCIES = []
64+ SYSTEM_TEST_EXTRAS = []
65+ SYSTEM_TEST_EXTRAS_BY_PYTHON = {}
3366
3467CURRENT_DIRECTORY = pathlib .Path (__file__ ).parent .absolute ()
3568
@@ -81,26 +114,41 @@ def lint_setup_py(session):
81114 session .run ("python" , "setup.py" , "check" , "--restructuredtext" , "--strict" )
82115
83116
117+ def install_unittest_dependencies (session , * constraints ):
118+ standard_deps = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_DEPENDENCIES
119+ session .install (* standard_deps , * constraints )
120+
121+ if UNIT_TEST_EXTERNAL_DEPENDENCIES :
122+ warnings .warn (
123+ "'unit_test_external_dependencies' is deprecated. Instead, please "
124+ "use 'unit_test_dependencies' or 'unit_test_local_dependencies'." ,
125+ DeprecationWarning ,
126+ )
127+ session .install (* UNIT_TEST_EXTERNAL_DEPENDENCIES , * constraints )
128+
129+ if UNIT_TEST_LOCAL_DEPENDENCIES :
130+ session .install (* UNIT_TEST_LOCAL_DEPENDENCIES , * constraints )
131+
132+ if UNIT_TEST_EXTRAS_BY_PYTHON :
133+ extras = UNIT_TEST_EXTRAS_BY_PYTHON .get (session .python , [])
134+ elif UNIT_TEST_EXTRAS :
135+ extras = UNIT_TEST_EXTRAS
136+ else :
137+ extras = []
138+
139+ if extras :
140+ session .install ("-e" , f".[{ ',' .join (extras )} ]" , * constraints )
141+ else :
142+ session .install ("-e" , "." , * constraints )
143+
144+
84145def default (session ):
85146 # Install all test dependencies, then install this package in-place.
86147
87148 constraints_path = str (
88149 CURRENT_DIRECTORY / "testing" / f"constraints-{ session .python } .txt"
89150 )
90- session .install (
91- "mock" ,
92- "asyncmock" ,
93- "pytest" ,
94- "pytest-cov" ,
95- "pytest-asyncio" ,
96- "-c" ,
97- constraints_path ,
98- )
99- session .install ("flask" , "-c" , constraints_path )
100- session .install ("webob" , "-c" , constraints_path )
101- session .install ("django" , "-c" , constraints_path )
102-
103- session .install ("-e" , "." , "-c" , constraints_path )
151+ install_unittest_dependencies (session , "-c" , constraints_path )
104152
105153 # Run py.test against the unit tests.
106154 session .run (
@@ -124,6 +172,35 @@ def unit(session):
124172 default (session )
125173
126174
175+ def install_systemtest_dependencies (session , * constraints ):
176+
177+ # Use pre-release gRPC for system tests.
178+ session .install ("--pre" , "grpcio" )
179+
180+ session .install (* SYSTEM_TEST_STANDARD_DEPENDENCIES , * constraints )
181+
182+ if SYSTEM_TEST_EXTERNAL_DEPENDENCIES :
183+ session .install (* SYSTEM_TEST_EXTERNAL_DEPENDENCIES , * constraints )
184+
185+ if SYSTEM_TEST_LOCAL_DEPENDENCIES :
186+ session .install ("-e" , * SYSTEM_TEST_LOCAL_DEPENDENCIES , * constraints )
187+
188+ if SYSTEM_TEST_DEPENDENCIES :
189+ session .install ("-e" , * SYSTEM_TEST_DEPENDENCIES , * constraints )
190+
191+ if SYSTEM_TEST_EXTRAS_BY_PYTHON :
192+ extras = SYSTEM_TEST_EXTRAS_BY_PYTHON .get (session .python , [])
193+ elif SYSTEM_TEST_EXTRAS :
194+ extras = SYSTEM_TEST_EXTRAS
195+ else :
196+ extras = []
197+
198+ if extras :
199+ session .install ("-e" , f".[{ ',' .join (extras )} ]" , * constraints )
200+ else :
201+ session .install ("-e" , "." , * constraints )
202+
203+
127204@nox .session (python = SYSTEM_TEST_PYTHON_VERSIONS )
128205def system (session ):
129206 """Run the system test suite."""
@@ -146,23 +223,7 @@ def system(session):
146223 if not system_test_exists and not system_test_folder_exists :
147224 session .skip ("System tests were not found" )
148225
149- # Use pre-release gRPC for system tests.
150- session .install ("--pre" , "grpcio" )
151-
152- # Install all test dependencies, then install this package into the
153- # virtualenv's dist-packages.
154- session .install (
155- "mock" ,
156- "pytest" ,
157- "google-cloud-testutils" ,
158- "google-cloud-bigquery" ,
159- "google-cloud-pubsub" ,
160- "google-cloud-storage" ,
161- "google-cloud-testutils" ,
162- "-c" ,
163- constraints_path ,
164- )
165- session .install ("-e" , "." , "-c" , constraints_path )
226+ install_systemtest_dependencies (session , "-c" , constraints_path )
166227
167228 # Run py.test against the system tests.
168229 if system_test_exists :
0 commit comments