|
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"] |
| 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 | + "testing", |
| 45 | +] |
| 46 | +UNIT_TEST_EXTRAS_BY_PYTHON = {} |
| 47 | + |
| 48 | +SYSTEM_TEST_PYTHON_VERSIONS = ["3.8"] |
| 49 | +SYSTEM_TEST_STANDARD_DEPENDENCIES = [ |
| 50 | + "mock", |
| 51 | + "pytest", |
| 52 | + "google-cloud-testutils", |
| 53 | +] |
| 54 | +SYSTEM_TEST_EXTERNAL_DEPENDENCIES = [] |
| 55 | +SYSTEM_TEST_LOCAL_DEPENDENCIES = [] |
| 56 | +SYSTEM_TEST_DEPENDENCIES = [] |
| 57 | +SYSTEM_TEST_EXTRAS = [] |
| 58 | +SYSTEM_TEST_EXTRAS_BY_PYTHON = {} |
33 | 59 |
|
34 | 60 | CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute() |
35 | 61 |
|
@@ -81,23 +107,41 @@ def lint_setup_py(session): |
81 | 107 | session.run("python", "setup.py", "check", "--restructuredtext", "--strict") |
82 | 108 |
|
83 | 109 |
|
| 110 | +def install_unittest_dependencies(session, *constraints): |
| 111 | + standard_deps = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_DEPENDENCIES |
| 112 | + session.install(*standard_deps, *constraints) |
| 113 | + |
| 114 | + if UNIT_TEST_EXTERNAL_DEPENDENCIES: |
| 115 | + warnings.warn( |
| 116 | + "'unit_test_external_dependencies' is deprecated. Instead, please " |
| 117 | + "use 'unit_test_dependencies' or 'unit_test_local_dependencies'.", |
| 118 | + DeprecationWarning, |
| 119 | + ) |
| 120 | + session.install(*UNIT_TEST_EXTERNAL_DEPENDENCIES, *constraints) |
| 121 | + |
| 122 | + if UNIT_TEST_LOCAL_DEPENDENCIES: |
| 123 | + session.install(*UNIT_TEST_LOCAL_DEPENDENCIES, *constraints) |
| 124 | + |
| 125 | + if UNIT_TEST_EXTRAS_BY_PYTHON: |
| 126 | + extras = UNIT_TEST_EXTRAS_BY_PYTHON.get(session.python, []) |
| 127 | + elif UNIT_TEST_EXTRAS: |
| 128 | + extras = UNIT_TEST_EXTRAS |
| 129 | + else: |
| 130 | + extras = [] |
| 131 | + |
| 132 | + if extras: |
| 133 | + session.install("-e", f".[{','.join(extras)}]", *constraints) |
| 134 | + else: |
| 135 | + session.install("-e", ".", *constraints) |
| 136 | + |
| 137 | + |
84 | 138 | def default(session): |
85 | 139 | # Install all test dependencies, then install this package in-place. |
86 | 140 |
|
87 | 141 | constraints_path = str( |
88 | 142 | CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt" |
89 | 143 | ) |
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", ".[testing]", "-c", constraints_path) |
| 144 | + install_unittest_dependencies(session, "-c", constraints_path) |
101 | 145 |
|
102 | 146 | # Run py.test against the unit tests. |
103 | 147 | session.run( |
@@ -121,6 +165,35 @@ def unit(session): |
121 | 165 | default(session) |
122 | 166 |
|
123 | 167 |
|
| 168 | +def install_systemtest_dependencies(session, *constraints): |
| 169 | + |
| 170 | + # Use pre-release gRPC for system tests. |
| 171 | + session.install("--pre", "grpcio") |
| 172 | + |
| 173 | + session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) |
| 174 | + |
| 175 | + if SYSTEM_TEST_EXTERNAL_DEPENDENCIES: |
| 176 | + session.install(*SYSTEM_TEST_EXTERNAL_DEPENDENCIES, *constraints) |
| 177 | + |
| 178 | + if SYSTEM_TEST_LOCAL_DEPENDENCIES: |
| 179 | + session.install("-e", *SYSTEM_TEST_LOCAL_DEPENDENCIES, *constraints) |
| 180 | + |
| 181 | + if SYSTEM_TEST_DEPENDENCIES: |
| 182 | + session.install("-e", *SYSTEM_TEST_DEPENDENCIES, *constraints) |
| 183 | + |
| 184 | + if SYSTEM_TEST_EXTRAS_BY_PYTHON: |
| 185 | + extras = SYSTEM_TEST_EXTRAS_BY_PYTHON.get(session.python, []) |
| 186 | + elif SYSTEM_TEST_EXTRAS: |
| 187 | + extras = SYSTEM_TEST_EXTRAS |
| 188 | + else: |
| 189 | + extras = [] |
| 190 | + |
| 191 | + if extras: |
| 192 | + session.install("-e", f".[{','.join(extras)}]", *constraints) |
| 193 | + else: |
| 194 | + session.install("-e", ".", *constraints) |
| 195 | + |
| 196 | + |
124 | 197 | @nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS) |
125 | 198 | def system(session): |
126 | 199 | """Run the system test suite.""" |
@@ -143,13 +216,7 @@ def system(session): |
143 | 216 | if not system_test_exists and not system_test_folder_exists: |
144 | 217 | session.skip("System tests were not found") |
145 | 218 |
|
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", ".[testing]", "-c", constraints_path) |
| 219 | + install_systemtest_dependencies(session, "-c", constraints_path) |
153 | 220 |
|
154 | 221 | # Run py.test against the system tests. |
155 | 222 | if system_test_exists: |
|