Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(python): use constraints files to check dependency lower bounds #869

Merged
merged 10 commits into from
Mar 23, 2021
19 changes: 17 additions & 2 deletions synthtool/gcp/templates/python_library/noxfile.py.j2
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 @@ DEFAULT_PYTHON_VERSION="{{ default_python_version }}"
SYSTEM_TEST_PYTHON_VERSIONS=[{% for v in system_test_python_versions %}"{{v}}"{% if not loop.last %},{% endif %}{% endfor %}]
UNIT_TEST_PYTHON_VERSIONS=[{% for v in unit_test_python_versions %}"{{v}}"{% if not loop.last %},{% endif %}{% endfor %}]

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

@nox.session(python=DEFAULT_PYTHON_VERSION)
def lint(session):
"""Run linters.
Expand Down Expand Up @@ -73,11 +76,17 @@ def lint_setup_py(session):
def default(session):
# Install all test dependencies, then install this package in-place.

constraints_path = (
CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt"
)
{%- if microgenerator %}
session.install("asyncmock", "pytest-asyncio")
{% endif %}
session.install("mock", "pytest", "pytest-cov", {% for d in unit_test_external_dependencies %}"{{d}}"{% if not loop.last %},{% endif %}{% endfor %})
session.install("-e", ".")
if constraints_path.exists():
session.install("-e", ".", "-c", str(constraints_path))
else:
session.install("-e", ".")
{% for dependency in unit_test_local_dependencies %}session.install("-e", "{{dependency}}"){% endfor %}
{% for dependency in unit_test_dependencies %}session.install("-e", "{{dependency}}"){% endfor %}

Expand All @@ -104,6 +113,9 @@ def unit(session):
@nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS)
def system(session):
"""Run the system test suite."""
constraints_path = (
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 @@ -130,7 +142,10 @@ def system(session):
{%- if system_test_local_dependencies %}
session.install("-e", {% for d in system_test_local_dependencies %}"{{d}}"{% if not loop.last %},{% endif %}{% endfor %})
{%- endif %}
session.install("-e", ".")
if constraints_path.exists():
session.install("-e", ".", "-c", str(constraints_path))
else:
session.install("-e", ".")


# Run py.test against the system tests.
Expand Down