Skip to content

Commit 1c1cb6c

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

File tree

2 files changed

+95
-27
lines changed

2 files changed

+95
-27
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: 93 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,48 @@
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", "pandas_gbq", "tests", "noxfile.py", "setup.py"]
3030

3131
DEFAULT_PYTHON_VERSION = "3.8"
32-
SYSTEM_TEST_PYTHON_VERSIONS = ["3.7", "3.8", "3.9", "3.10"]
32+
3333
UNIT_TEST_PYTHON_VERSIONS = ["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+
"freezegun",
43+
]
44+
UNIT_TEST_LOCAL_DEPENDENCIES = []
45+
UNIT_TEST_DEPENDENCIES = []
46+
UNIT_TEST_EXTRAS = [
47+
"tqdm",
48+
]
49+
UNIT_TEST_EXTRAS_BY_PYTHON = {
50+
"3.9": [],
51+
}
52+
53+
SYSTEM_TEST_PYTHON_VERSIONS = ["3.7", "3.8", "3.9", "3.10"]
54+
SYSTEM_TEST_STANDARD_DEPENDENCIES = [
55+
"mock",
56+
"pytest",
57+
"google-cloud-testutils",
58+
]
59+
SYSTEM_TEST_EXTERNAL_DEPENDENCIES = []
60+
SYSTEM_TEST_LOCAL_DEPENDENCIES = []
61+
SYSTEM_TEST_DEPENDENCIES = []
62+
SYSTEM_TEST_EXTRAS = [
63+
"tqdm",
64+
]
65+
SYSTEM_TEST_EXTRAS_BY_PYTHON = {}
3466

3567
CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute()
3668

@@ -82,28 +114,41 @@ def lint_setup_py(session):
82114
session.run("python", "setup.py", "check", "--restructuredtext", "--strict")
83115

84116

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

88148
constraints_path = str(
89149
CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt"
90150
)
91-
session.install(
92-
"mock",
93-
"asyncmock",
94-
"pytest",
95-
"pytest-cov",
96-
"pytest-asyncio",
97-
"-c",
98-
constraints_path,
99-
)
100-
session.install("freezegun", "-c", constraints_path)
101-
102-
if session.python == "3.9":
103-
extras = ""
104-
else:
105-
extras = "[tqdm]"
106-
session.install("-e", f".{extras}", "-c", constraints_path)
151+
install_unittest_dependencies(session, "-c", constraints_path)
107152

108153
# Run py.test against the unit tests.
109154
session.run(
@@ -127,6 +172,35 @@ def unit(session):
127172
default(session)
128173

129174

175+
def install_systemtest_dependencies(session, *constraints):
176+
177+
# Use pre-release gRPC for system tests.
178+
session.install("--pre", "grpcio")
179+
180+
session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints)
181+
182+
if SYSTEM_TEST_EXTERNAL_DEPENDENCIES:
183+
session.install(*SYSTEM_TEST_EXTERNAL_DEPENDENCIES, *constraints)
184+
185+
if SYSTEM_TEST_LOCAL_DEPENDENCIES:
186+
session.install("-e", *SYSTEM_TEST_LOCAL_DEPENDENCIES, *constraints)
187+
188+
if SYSTEM_TEST_DEPENDENCIES:
189+
session.install("-e", *SYSTEM_TEST_DEPENDENCIES, *constraints)
190+
191+
if SYSTEM_TEST_EXTRAS_BY_PYTHON:
192+
extras = SYSTEM_TEST_EXTRAS_BY_PYTHON.get(session.python, [])
193+
elif SYSTEM_TEST_EXTRAS:
194+
extras = SYSTEM_TEST_EXTRAS
195+
else:
196+
extras = []
197+
198+
if extras:
199+
session.install("-e", f".[{','.join(extras)}]", *constraints)
200+
else:
201+
session.install("-e", ".", *constraints)
202+
203+
130204
@nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS)
131205
def system(session):
132206
"""Run the system test suite."""
@@ -149,13 +223,7 @@ def system(session):
149223
if not system_test_exists and not system_test_folder_exists:
150224
session.skip("System tests were not found")
151225

152-
# Use pre-release gRPC for system tests.
153-
session.install("--pre", "grpcio")
154-
155-
# Install all test dependencies, then install this package into the
156-
# virtualenv's dist-packages.
157-
session.install("mock", "pytest", "google-cloud-testutils", "-c", constraints_path)
158-
session.install("-e", ".[tqdm]", "-c", constraints_path)
226+
install_systemtest_dependencies(session, "-c", constraints_path)
159227

160228
# Run py.test against the system tests.
161229
if system_test_exists:

0 commit comments

Comments
 (0)