1818
1919from __future__ import absolute_import
2020import os
21+ import pathlib
2122import shutil
2223
2324import nox
3031SYSTEM_TEST_PYTHON_VERSIONS = ["3.8" ]
3132UNIT_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'
3437nox .options .sessions = [
3538 "unit" ,
@@ -59,16 +62,9 @@ def lint(session):
5962 session .run ("flake8" , "google" , "tests" )
6063
6164
62- @nox .session (python = "3.6" )
65+ @nox .session (python = DEFAULT_PYTHON_VERSION )
6366def blacken (session ):
64- """Run black.
65-
66- Format code to uniform standard.
67-
68- This currently uses Python 3.6 due to the automated Kokoro run of synthtool.
69- That run uses an image that doesn't have 3.6 installed. Before updating this
70- check the state of the `gcp_ubuntu_config` we use for that Kokoro run.
71- """
67+ """Run black. Format code to uniform standard."""
7268 session .install (BLACK_VERSION )
7369 session .run (
7470 "black" , * BLACK_PATHS ,
@@ -84,13 +80,15 @@ def lint_setup_py(session):
8480
8581def default (session ):
8682 # Install all test dependencies, then install this package in-place.
87- session .install ("asyncmock" , "pytest-asyncio" )
8883
89- session . install (
90- "mock" , "pytest" , "pytest-cov" ,
84+ constraints_path = str (
85+ CURRENT_DIRECTORY / "testing" / f"constraints- { session . python } .txt"
9186 )
87+ session .install ("asyncmock" , "pytest-asyncio" , "-c" , constraints_path )
9288
93- session .install ("-e" , "." )
89+ session .install ("mock" , "pytest" , "pytest-cov" , "-c" , constraints_path )
90+
91+ session .install ("-e" , "." , "-c" , constraints_path )
9492
9593 # Run py.test against the unit tests.
9694 session .run (
@@ -117,15 +115,15 @@ def unit(session):
117115@nox .session (python = SYSTEM_TEST_PYTHON_VERSIONS )
118116def system (session ):
119117 """Run the system test suite."""
118+ constraints_path = str (
119+ CURRENT_DIRECTORY / "testing" / f"constraints-{ session .python } .txt"
120+ )
120121 system_test_path = os .path .join ("tests" , "system.py" )
121122 system_test_folder_path = os .path .join ("tests" , "system" )
122123
123124 # Check the value of `RUN_SYSTEM_TESTS` env var. It defaults to true.
124125 if os .environ .get ("RUN_SYSTEM_TESTS" , "true" ) == "false" :
125126 session .skip ("RUN_SYSTEM_TESTS is set to false, skipping" )
126- # Sanity check: Only run tests if the environment variable is set.
127- if not os .environ .get ("GOOGLE_APPLICATION_CREDENTIALS" , "" ):
128- session .skip ("Credentials must be set via environment variable" )
129127 # Install pyopenssl for mTLS testing.
130128 if os .environ .get ("GOOGLE_API_USE_CLIENT_CERTIFICATE" , "false" ) == "true" :
131129 session .install ("pyopenssl" )
@@ -141,10 +139,8 @@ def system(session):
141139
142140 # Install all test dependencies, then install this package into the
143141 # virtualenv's dist-packages.
144- session .install (
145- "mock" , "pytest" , "google-cloud-testutils" ,
146- )
147- session .install ("-e" , "." )
142+ session .install ("mock" , "pytest" , "google-cloud-testutils" , "-c" , constraints_path )
143+ session .install ("-e" , "." , "-c" , constraints_path )
148144
149145 # Run py.test against the system tests.
150146 if system_test_exists :
0 commit comments