Skip to content
This repository was archived by the owner on Mar 15, 2025. It is now read-only.

Commit ff25061

Browse files
test(python): use constraints files to check dependency lower bounds
Use a constraints file when installing dependencies for system and unit tests nox sessions. https://pip.pypa.io/en/stable/user_guide/#constraints-files > Constraints files are requirements files that **only control which version of a requirement is installed, not whether it is installed or not**. Their syntax and contents is nearly identical to Requirements Files. There is one key difference: Including a package in a constraints file does not trigger installation of the package. ``` testing ├── constraints-3.10.txt ├── constraints-3.11.txt ├── constraints-3.6.txt ├── constraints-3.7.txt ├── constraints-3.8.txt └── constraints-3.9.txt ``` Going forward, one constraints file (currently 3.6) will be populated with every library requirement and extra listed in the `setup.py`. The constraints file will pin each requirement to the lower bound. This ensures that library maintainers will see test failures if they forget to update a lower bound on a dependency. See googleapis/python-bigquery#263 for an example Source-Author: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com> Source-Date: Tue Mar 23 10:52:02 2021 -0600 Source-Repo: googleapis/synthtool Source-Sha: 86ed43d4f56e6404d068e62e497029018879c771 Source-Link: googleapis/synthtool@86ed43d
1 parent 370e285 commit ff25061

2 files changed

Lines changed: 16 additions & 10 deletions

File tree

noxfile.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
from __future__ import absolute_import
2020
import os
21+
import pathlib
2122
import shutil
2223

2324
import nox
@@ -30,6 +31,8 @@
3031
SYSTEM_TEST_PYTHON_VERSIONS = ["3.8"]
3132
UNIT_TEST_PYTHON_VERSIONS = ["3.6", "3.7", "3.8", "3.9"]
3233

34+
CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute()
35+
3336
# 'docfx' is excluded since it only needs to run in 'docs-presubmit'
3437
nox.options.sessions = [
3538
"unit",
@@ -114,13 +117,15 @@ def lint_setup_py(session):
114117

115118
def default(session):
116119
# Install all test dependencies, then install this package in-place.
117-
session.install("asyncmock", "pytest-asyncio")
118120

119-
session.install(
120-
"mock", "pytest", "pytest-cov",
121+
constraints_path = str(
122+
CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt"
121123
)
124+
session.install("asyncmock", "pytest-asyncio", "-c", constraints_path)
122125

123-
session.install("-e", ".")
126+
session.install("mock", "pytest", "pytest-cov", "-c", constraints_path)
127+
128+
session.install("-e", ".", "-c", constraints_path)
124129

125130
# Run py.test against the unit tests.
126131
session.run(
@@ -147,6 +152,9 @@ def unit(session):
147152
@nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS)
148153
def system(session):
149154
"""Run the system test suite."""
155+
constraints_path = str(
156+
CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt"
157+
)
150158
system_test_path = os.path.join("tests", "system.py")
151159
system_test_folder_path = os.path.join("tests", "system")
152160

@@ -171,10 +179,8 @@ def system(session):
171179

172180
# Install all test dependencies, then install this package into the
173181
# virtualenv's dist-packages.
174-
session.install(
175-
"mock", "pytest", "google-cloud-testutils",
176-
)
177-
session.install("-e", ".")
182+
session.install("mock", "pytest", "google-cloud-testutils", "-c", constraints_path)
183+
session.install("-e", ".", "-c", constraints_path)
178184

179185
# Run py.test against the system tests.
180186
if system_test_exists:

synth.metadata

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
"git": {
2020
"name": "synthtool",
2121
"remote": "https://github.com/googleapis/synthtool.git",
22-
"sha": "f5c5904fb0c6aa3b3730eadf4e5a4485afc65726"
22+
"sha": "86ed43d4f56e6404d068e62e497029018879c771"
2323
}
2424
},
2525
{
2626
"git": {
2727
"name": "synthtool",
2828
"remote": "https://github.com/googleapis/synthtool.git",
29-
"sha": "f5c5904fb0c6aa3b3730eadf4e5a4485afc65726"
29+
"sha": "86ed43d4f56e6404d068e62e497029018879c771"
3030
}
3131
}
3232
],

0 commit comments

Comments
 (0)