Skip to content

Commit 3a4ed93

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

File tree

2 files changed

+89
-23
lines changed

2 files changed

+89
-23
lines changed

packages/google-auth-oauthlib/.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/google-auth-oauthlib/noxfile.py

Lines changed: 87 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,42 @@
2020
import os
2121
import pathlib
2222
import shutil
23+
import warnings
2324

2425
import nox
2526

26-
2727
BLACK_VERSION = "black==22.3.0"
2828
BLACK_PATHS = ["docs", "google_auth_oauthlib", "tests", "noxfile.py", "setup.py"]
2929

3030
DEFAULT_PYTHON_VERSION = "3.8"
31-
SYSTEM_TEST_PYTHON_VERSIONS = ["3.8"]
31+
3232
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+
"click",
42+
]
43+
UNIT_TEST_LOCAL_DEPENDENCIES = []
44+
UNIT_TEST_DEPENDENCIES = []
45+
UNIT_TEST_EXTRAS = []
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 = {}
3359

3460
CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute()
3561

@@ -81,24 +107,41 @@ def lint_setup_py(session):
81107
session.run("python", "setup.py", "check", "--restructuredtext", "--strict")
82108

83109

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+
84138
def default(session):
85139
# Install all test dependencies, then install this package in-place.
86140

87141
constraints_path = str(
88142
CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt"
89143
)
90-
session.install(
91-
"mock",
92-
"asyncmock",
93-
"pytest",
94-
"pytest-cov",
95-
"pytest-asyncio",
96-
"-c",
97-
constraints_path,
98-
)
99-
session.install("click", "-c", constraints_path)
100-
101-
session.install("-e", ".", "-c", constraints_path)
144+
install_unittest_dependencies(session, "-c", constraints_path)
102145

103146
# Run py.test against the unit tests.
104147
session.run(
@@ -122,6 +165,35 @@ def unit(session):
122165
default(session)
123166

124167

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+
125197
@nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS)
126198
def system(session):
127199
"""Run the system test suite."""
@@ -144,13 +216,7 @@ def system(session):
144216
if not system_test_exists and not system_test_folder_exists:
145217
session.skip("System tests were not found")
146218

147-
# Use pre-release gRPC for system tests.
148-
session.install("--pre", "grpcio")
149-
150-
# Install all test dependencies, then install this package into the
151-
# virtualenv's dist-packages.
152-
session.install("mock", "pytest", "google-cloud-testutils", "-c", constraints_path)
153-
session.install("-e", ".", "-c", constraints_path)
219+
install_systemtest_dependencies(session, "-c", constraints_path)
154220

155221
# Run py.test against the system tests.
156222
if system_test_exists:

0 commit comments

Comments
 (0)