|
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( |
@@ -142,6 +184,35 @@ def unit(session): |
142 | 184 | default(session) |
143 | 185 |
|
144 | 186 |
|
| 187 | +def install_systemtest_dependencies(session, *constraints): |
| 188 | + |
| 189 | + # Use pre-release gRPC for system tests. |
| 190 | + session.install("--pre", "grpcio") |
| 191 | + |
| 192 | + session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) |
| 193 | + |
| 194 | + if SYSTEM_TEST_EXTERNAL_DEPENDENCIES: |
| 195 | + session.install(*SYSTEM_TEST_EXTERNAL_DEPENDENCIES, *constraints) |
| 196 | + |
| 197 | + if SYSTEM_TEST_LOCAL_DEPENDENCIES: |
| 198 | + session.install("-e", *SYSTEM_TEST_LOCAL_DEPENDENCIES, *constraints) |
| 199 | + |
| 200 | + if SYSTEM_TEST_DEPENDENCIES: |
| 201 | + session.install("-e", *SYSTEM_TEST_DEPENDENCIES, *constraints) |
| 202 | + |
| 203 | + if SYSTEM_TEST_EXTRAS_BY_PYTHON: |
| 204 | + extras = SYSTEM_TEST_EXTRAS_BY_PYTHON.get(session.python, []) |
| 205 | + elif SYSTEM_TEST_EXTRAS: |
| 206 | + extras = SYSTEM_TEST_EXTRAS |
| 207 | + else: |
| 208 | + extras = [] |
| 209 | + |
| 210 | + if extras: |
| 211 | + session.install("-e", f".[{','.join(extras)}]", *constraints) |
| 212 | + else: |
| 213 | + session.install("-e", ".", *constraints) |
| 214 | + |
| 215 | + |
145 | 216 | @nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS) |
146 | 217 | def system(session): |
147 | 218 | """Run the system test suite.""" |
@@ -172,13 +243,7 @@ def system(session): |
172 | 243 | if not system_test_exists and not system_test_folder_exists: |
173 | 244 | session.skip("System tests were not found") |
174 | 245 |
|
175 | | - # Use pre-release gRPC for system tests. |
176 | | - session.install("--pre", "grpcio") |
177 | | - |
178 | | - # Install all test dependencies, then install this package into the |
179 | | - # virtualenv's dist-packages. |
180 | | - session.install("mock", "pytest", "google-cloud-testutils", "-c", constraints_path) |
181 | | - session.install("-e", ".[tracing]", "-c", constraints_path) |
| 246 | + install_systemtest_dependencies(session, "-c", constraints_path) |
182 | 247 |
|
183 | 248 | # Run py.test against the system tests. |
184 | 249 | if system_test_exists: |
|
0 commit comments