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
@@ -81,23 +105,41 @@ def lint_setup_py(session):
81105 session .run ("python" , "setup.py" , "check" , "--restructuredtext" , "--strict" )
82106
83107
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+
84136def default (session ):
85137 # Install all test dependencies, then install this package in-place.
86138
87139 constraints_path = str (
88140 CURRENT_DIRECTORY / "testing" / f"constraints-{ session .python } .txt"
89141 )
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 )
101143
102144 # Run py.test against the unit tests.
103145 session .run (
@@ -121,6 +163,35 @@ def unit(session):
121163 default (session )
122164
123165
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+
124195@nox .session (python = SYSTEM_TEST_PYTHON_VERSIONS )
125196def system (session ):
126197 """Run the system test suite."""
@@ -143,13 +214,7 @@ def system(session):
143214 if not system_test_exists and not system_test_folder_exists :
144215 session .skip ("System tests were not found" )
145216
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 )
153218
154219 # Run py.test against the system tests.
155220 if system_test_exists :
0 commit comments