Skip to content

Commit

Permalink
test(python): use constraints files to check dependency lower bounds
Browse files Browse the repository at this point in the history
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 <[email protected]>
Source-Date: Tue Mar 23 10:52:02 2021 -0600
Source-Repo: googleapis/synthtool
Source-Sha: 86ed43d4f56e6404d068e62e497029018879c771
Source-Link: googleapis/synthtool@86ed43d
  • Loading branch information
yoshi-automation committed Mar 23, 2021
1 parent e644c6b commit 5a3f0f0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
20 changes: 13 additions & 7 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from __future__ import absolute_import
import os
import pathlib
import shutil

import nox
Expand All @@ -30,6 +31,8 @@
SYSTEM_TEST_PYTHON_VERSIONS = ["2.7", "3.8"]
UNIT_TEST_PYTHON_VERSIONS = ["2.7", "3.6", "3.7", "3.8", "3.9"]

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

# 'docfx' is excluded since it only needs to run in 'docs-presubmit'
nox.options.sessions = [
"unit",
Expand Down Expand Up @@ -84,11 +87,13 @@ def lint_setup_py(session):

def default(session):
# Install all test dependencies, then install this package in-place.
session.install(
"mock", "pytest", "pytest-cov",

constraints_path = str(
CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt"
)
session.install("mock", "pytest", "pytest-cov", "-c", constraints_path)

session.install("-e", ".")
session.install("-e", ".", "-c", constraints_path)

# Run py.test against the unit tests.
session.run(
Expand All @@ -115,6 +120,9 @@ def unit(session):
@nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS)
def system(session):
"""Run the system test suite."""
constraints_path = str(
CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt"
)
system_test_path = os.path.join("tests", "system.py")
system_test_folder_path = os.path.join("tests", "system")

Expand All @@ -139,10 +147,8 @@ def system(session):

# Install all test dependencies, then install this package into the
# virtualenv's dist-packages.
session.install(
"mock", "pytest", "google-cloud-testutils",
)
session.install("-e", ".")
session.install("mock", "pytest", "google-cloud-testutils", "-c", constraints_path)
session.install("-e", ".", "-c", constraints_path)

# Run py.test against the system tests.
if system_test_exists:
Expand Down
2 changes: 1 addition & 1 deletion synth.metadata
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"git": {
"name": "synthtool",
"remote": "https://github.com/googleapis/synthtool.git",
"sha": "f5c5904fb0c6aa3b3730eadf4e5a4485afc65726"
"sha": "86ed43d4f56e6404d068e62e497029018879c771"
}
}
],
Expand Down

0 comments on commit 5a3f0f0

Please sign in to comment.