Skip to content

Commit 16b87d0

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

File tree

2 files changed

+87
-22
lines changed

2 files changed

+87
-22
lines changed

.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

noxfile.py

Lines changed: 85 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,40 @@
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", "db_dtypes", "tests", "noxfile.py", "setup.py"]
3030

3131
DEFAULT_PYTHON_VERSION = "3.8"
32-
SYSTEM_TEST_PYTHON_VERSIONS = ["3.8"]
32+
3333
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+
UNIT_TEST_EXTRAS_BY_PYTHON = {}
46+
47+
SYSTEM_TEST_PYTHON_VERSIONS = ["3.8"]
48+
SYSTEM_TEST_STANDARD_DEPENDENCIES = [
49+
"mock",
50+
"pytest",
51+
"google-cloud-testutils",
52+
]
53+
SYSTEM_TEST_EXTERNAL_DEPENDENCIES = []
54+
SYSTEM_TEST_LOCAL_DEPENDENCIES = []
55+
SYSTEM_TEST_DEPENDENCIES = []
56+
SYSTEM_TEST_EXTRAS = []
57+
SYSTEM_TEST_EXTRAS_BY_PYTHON = {}
3458

3559
CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute()
3660

@@ -84,23 +108,41 @@ def lint_setup_py(session):
84108
session.run("python", "setup.py", "check", "--restructuredtext", "--strict")
85109

86110

111+
def install_unittest_dependencies(session, *constraints):
112+
standard_deps = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_DEPENDENCIES
113+
session.install(*standard_deps, *constraints)
114+
115+
if UNIT_TEST_EXTERNAL_DEPENDENCIES:
116+
warnings.warn(
117+
"'unit_test_external_dependencies' is deprecated. Instead, please "
118+
"use 'unit_test_dependencies' or 'unit_test_local_dependencies'.",
119+
DeprecationWarning,
120+
)
121+
session.install(*UNIT_TEST_EXTERNAL_DEPENDENCIES, *constraints)
122+
123+
if UNIT_TEST_LOCAL_DEPENDENCIES:
124+
session.install(*UNIT_TEST_LOCAL_DEPENDENCIES, *constraints)
125+
126+
if UNIT_TEST_EXTRAS_BY_PYTHON:
127+
extras = UNIT_TEST_EXTRAS_BY_PYTHON.get(session.python, [])
128+
elif UNIT_TEST_EXTRAS:
129+
extras = UNIT_TEST_EXTRAS
130+
else:
131+
extras = []
132+
133+
if extras:
134+
session.install("-e", f".[{','.join(extras)}]", *constraints)
135+
else:
136+
session.install("-e", ".", *constraints)
137+
138+
87139
def default(session, tests_path):
88140
# Install all test dependencies, then install this package in-place.
89141

90142
constraints_path = str(
91143
CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt"
92144
)
93-
session.install(
94-
"mock",
95-
"asyncmock",
96-
"pytest",
97-
"pytest-cov",
98-
"pytest-asyncio",
99-
"-c",
100-
constraints_path,
101-
)
102-
103-
session.install("-e", ".", "-c", constraints_path)
145+
install_unittest_dependencies(session, "-c", constraints_path)
104146

105147
# Run py.test against the unit tests.
106148
session.run(
@@ -218,6 +260,35 @@ def unit_prerelease(session):
218260
prerelease(session, os.path.join("tests", "unit"))
219261

220262

263+
def install_systemtest_dependencies(session, *constraints):
264+
265+
# Use pre-release gRPC for system tests.
266+
session.install("--pre", "grpcio")
267+
268+
session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints)
269+
270+
if SYSTEM_TEST_EXTERNAL_DEPENDENCIES:
271+
session.install(*SYSTEM_TEST_EXTERNAL_DEPENDENCIES, *constraints)
272+
273+
if SYSTEM_TEST_LOCAL_DEPENDENCIES:
274+
session.install("-e", *SYSTEM_TEST_LOCAL_DEPENDENCIES, *constraints)
275+
276+
if SYSTEM_TEST_DEPENDENCIES:
277+
session.install("-e", *SYSTEM_TEST_DEPENDENCIES, *constraints)
278+
279+
if SYSTEM_TEST_EXTRAS_BY_PYTHON:
280+
extras = SYSTEM_TEST_EXTRAS_BY_PYTHON.get(session.python, [])
281+
elif SYSTEM_TEST_EXTRAS:
282+
extras = SYSTEM_TEST_EXTRAS
283+
else:
284+
extras = []
285+
286+
if extras:
287+
session.install("-e", f".[{','.join(extras)}]", *constraints)
288+
else:
289+
session.install("-e", ".", *constraints)
290+
291+
221292
@nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS)
222293
def system(session):
223294
"""Run the system test suite."""
@@ -240,13 +311,7 @@ def system(session):
240311
if not system_test_exists and not system_test_folder_exists:
241312
session.skip("System tests were not found")
242313

243-
# Use pre-release gRPC for system tests.
244-
session.install("--pre", "grpcio")
245-
246-
# Install all test dependencies, then install this package into the
247-
# virtualenv's dist-packages.
248-
session.install("mock", "pytest", "google-cloud-testutils", "-c", constraints_path)
249-
session.install("-e", ".", "-c", constraints_path)
314+
install_systemtest_dependencies(session, "-c", constraints_path)
250315

251316
# Run py.test against the system tests.
252317
if system_test_exists:

0 commit comments

Comments
 (0)