Skip to content

Commit db9278e

Browse files
chore(python): refactor unit / system test dependency install (#444)
Source-Link: googleapis/synthtool@993985f Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:1894490910e891a385484514b22eb5133578897eb5b3c380e6d8ad475c6647cd
1 parent 1a7a437 commit db9278e

File tree

2 files changed

+109
-34
lines changed

2 files changed

+109
-34
lines changed

packages/sqlalchemy-bigquery/.github/.OwlBot.lock.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@
1313
# limitations under the License.
1414
docker:
1515
image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest
16-
digest: sha256:b3500c053313dc34e07b1632ba9e4e589f4f77036a7cf39e1fe8906811ae0fce
17-
# created: 2022-04-01T01:42:03.609279246Z
16+
digest: sha256:1894490910e891a385484514b22eb5133578897eb5b3c380e6d8ad475c6647cd
17+
# created: 2022-04-01T15:48:07.524222836Z

packages/sqlalchemy-bigquery/noxfile.py

Lines changed: 107 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,64 @@
2121
import pathlib
2222
import re
2323
import shutil
24+
import warnings
2425

2526
import nox
2627

27-
2828
BLACK_VERSION = "black==22.3.0"
2929
BLACK_PATHS = ["docs", "sqlalchemy_bigquery", "tests", "noxfile.py", "setup.py"]
3030

3131
DEFAULT_PYTHON_VERSION = "3.8"
3232

33+
UNIT_TEST_PYTHON_VERSIONS = ["3.6", "3.7", "3.8", "3.9", "3.10"]
34+
UNIT_TEST_STANDARD_DEPENDENCIES = [
35+
"mock",
36+
"asyncmock",
37+
"pytest",
38+
"pytest-cov",
39+
"pytest-asyncio",
40+
]
41+
UNIT_TEST_EXTERNAL_DEPENDENCIES = []
42+
UNIT_TEST_LOCAL_DEPENDENCIES = []
43+
UNIT_TEST_DEPENDENCIES = []
44+
UNIT_TEST_EXTRAS = [
45+
"tests",
46+
]
47+
UNIT_TEST_EXTRAS_BY_PYTHON = {
48+
"3.8": [
49+
"tests",
50+
"alembic",
51+
],
52+
"3.10": [
53+
"tests",
54+
"geography",
55+
],
56+
}
57+
58+
3359
# We're using two Python versions to test with sqlalchemy 1.3 and 1.4.
3460
SYSTEM_TEST_PYTHON_VERSIONS = ["3.8", "3.10"]
35-
UNIT_TEST_PYTHON_VERSIONS = ["3.6", "3.7", "3.8", "3.9", "3.10"]
61+
SYSTEM_TEST_STANDARD_DEPENDENCIES = [
62+
"mock",
63+
"pytest",
64+
"google-cloud-testutils",
65+
]
66+
SYSTEM_TEST_EXTERNAL_DEPENDENCIES = []
67+
SYSTEM_TEST_LOCAL_DEPENDENCIES = []
68+
SYSTEM_TEST_DEPENDENCIES = []
69+
SYSTEM_TEST_EXTRAS = [
70+
"tests",
71+
]
72+
SYSTEM_TEST_EXTRAS_BY_PYTHON = {
73+
"3.8": [
74+
"tests",
75+
"alembic",
76+
],
77+
"3.10": [
78+
"tests",
79+
"geography",
80+
],
81+
}
3682

3783
CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute()
3884

@@ -85,29 +131,41 @@ def lint_setup_py(session):
85131
session.run("python", "setup.py", "check", "--restructuredtext", "--strict")
86132

87133

134+
def install_unittest_dependencies(session, *constraints):
135+
standard_deps = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_DEPENDENCIES
136+
session.install(*standard_deps, *constraints)
137+
138+
if UNIT_TEST_EXTERNAL_DEPENDENCIES:
139+
warnings.warn(
140+
"'unit_test_external_dependencies' is deprecated. Instead, please "
141+
"use 'unit_test_dependencies' or 'unit_test_local_dependencies'.",
142+
DeprecationWarning,
143+
)
144+
session.install(*UNIT_TEST_EXTERNAL_DEPENDENCIES, *constraints)
145+
146+
if UNIT_TEST_LOCAL_DEPENDENCIES:
147+
session.install(*UNIT_TEST_LOCAL_DEPENDENCIES, *constraints)
148+
149+
if UNIT_TEST_EXTRAS_BY_PYTHON:
150+
extras = UNIT_TEST_EXTRAS_BY_PYTHON.get(session.python, [])
151+
elif UNIT_TEST_EXTRAS:
152+
extras = UNIT_TEST_EXTRAS
153+
else:
154+
extras = []
155+
156+
if extras:
157+
session.install("-e", f".[{','.join(extras)}]", *constraints)
158+
else:
159+
session.install("-e", ".", *constraints)
160+
161+
88162
def default(session):
89163
# Install all test dependencies, then install this package in-place.
90164

91165
constraints_path = str(
92166
CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt"
93167
)
94-
session.install(
95-
"mock",
96-
"asyncmock",
97-
"pytest",
98-
"pytest-cov",
99-
"pytest-asyncio",
100-
"-c",
101-
constraints_path,
102-
)
103-
104-
if session.python == "3.8":
105-
extras = "[tests,alembic]"
106-
elif session.python == "3.10":
107-
extras = "[tests,geography]"
108-
else:
109-
extras = "[tests]"
110-
session.install("-e", f".{extras}", "-c", constraints_path)
168+
install_unittest_dependencies(session, "-c", constraints_path)
111169

112170
# Run py.test against the unit tests.
113171
session.run(
@@ -131,6 +189,35 @@ def unit(session):
131189
default(session)
132190

133191

192+
def install_systemtest_dependencies(session, *constraints):
193+
194+
# Use pre-release gRPC for system tests.
195+
session.install("--pre", "grpcio")
196+
197+
session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints)
198+
199+
if SYSTEM_TEST_EXTERNAL_DEPENDENCIES:
200+
session.install(*SYSTEM_TEST_EXTERNAL_DEPENDENCIES, *constraints)
201+
202+
if SYSTEM_TEST_LOCAL_DEPENDENCIES:
203+
session.install("-e", *SYSTEM_TEST_LOCAL_DEPENDENCIES, *constraints)
204+
205+
if SYSTEM_TEST_DEPENDENCIES:
206+
session.install("-e", *SYSTEM_TEST_DEPENDENCIES, *constraints)
207+
208+
if SYSTEM_TEST_EXTRAS_BY_PYTHON:
209+
extras = SYSTEM_TEST_EXTRAS_BY_PYTHON.get(session.python, [])
210+
elif SYSTEM_TEST_EXTRAS:
211+
extras = SYSTEM_TEST_EXTRAS
212+
else:
213+
extras = []
214+
215+
if extras:
216+
session.install("-e", f".[{','.join(extras)}]", *constraints)
217+
else:
218+
session.install("-e", ".", *constraints)
219+
220+
134221
@nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS)
135222
def system(session):
136223
"""Run the system test suite."""
@@ -153,19 +240,7 @@ def system(session):
153240
if not system_test_exists and not system_test_folder_exists:
154241
session.skip("System tests were not found")
155242

156-
# Use pre-release gRPC for system tests.
157-
session.install("--pre", "grpcio")
158-
159-
# Install all test dependencies, then install this package into the
160-
# virtualenv's dist-packages.
161-
session.install("mock", "pytest", "google-cloud-testutils", "-c", constraints_path)
162-
if session.python == "3.8":
163-
extras = "[tests,alembic]"
164-
elif session.python == "3.10":
165-
extras = "[tests,geography]"
166-
else:
167-
extras = "[tests]"
168-
session.install("-e", f".{extras}", "-c", constraints_path)
243+
install_systemtest_dependencies(session, "-c", constraints_path)
169244

170245
# Run py.test against the system tests.
171246
if system_test_exists:

0 commit comments

Comments
 (0)