1515from __future__ import absolute_import
1616import os
1717import pathlib
18+ import pytest
1819import re
1920import shutil
2021import unittest
3637# 'docfx' is excluded since it only needs to run in 'docs-presubmit'
3738nox .options .sessions = [
3839 "unit" ,
39- "unit_grpc_gcp" ,
40- "unit_wo_grpc" ,
41- "unit_w_prerelease_deps" ,
42- "unit_w_async_rest_extra" ,
40+ "prerelease_deps" ,
4341 "cover" ,
44- "pytype" ,
45- "mypy" ,
4642 "lint" ,
4743 "lint_setup_py" ,
4844 "blacken" ,
@@ -70,6 +66,20 @@ def lint(session):
7066 )
7167 session .run ("flake8" , "google" , "tests" )
7268
69+ """Run type-checking."""
70+ session .install (".[grpc]" , "pytype" )
71+ session .run ("pytype" )
72+
73+ session .install (".[grpc,async_rest]" , "mypy" )
74+ session .install (
75+ "types-setuptools" ,
76+ "types-requests" ,
77+ "types-protobuf" ,
78+ "types-dataclasses" ,
79+ "types-mock; python_version=='3.7'" ,
80+ )
81+ session .run ("mypy" , "google" , "tests" )
82+
7383
7484@nox .session (python = DEFAULT_PYTHON_VERSION )
7585def blacken (session ):
@@ -214,47 +224,42 @@ def default(session, install_grpc=True, prerelease=False, install_async_rest=Fal
214224 session .run (* pytest_args )
215225
216226
227+ @pytest .mark .parametrize (
228+ "install_grpc_gcp,install_grpc,install_async_rest" ,
229+ [
230+ (False , True , False ), # Run unit tests with grpcio installed
231+ (True , True , False ), # Run unit tests with grpcio/grpcio-gcp installed
232+ (False , False , False ), # Run unit tests without grpcio installed
233+ (False , True , True ), # Run unit tests with grpcio and async rest installed
234+ ],
235+ )
217236@nox .session (python = PYTHON_VERSIONS )
218- def unit (session ):
219- """Run the unit test suite."""
220- default (session )
221-
222-
223- @nox .session (python = PYTHON_VERSIONS )
224- def unit_w_prerelease_deps (session ):
237+ def unit (session , install_grpc_gcp , install_grpc , install_async_rest ):
225238 """Run the unit test suite."""
226- default (session , prerelease = True )
227239
228-
229- @nox .session (python = PYTHON_VERSIONS )
230- def unit_grpc_gcp (session ):
231- """
232- Run the unit test suite with grpcio-gcp installed.
233- `grpcio-gcp` doesn't support protobuf 4+.
234- Remove extra `grpcgcp` when protobuf 3.x is dropped.
235- https://github.com/googleapis/python-api-core/issues/594
236- """
237- constraints_path = str (
238- CURRENT_DIRECTORY / "testing" / f"constraints-{ session .python } .txt"
240+ # `grpcio-gcp` doesn't support protobuf 4+.
241+ # Remove extra `grpcgcp` when protobuf 3.x is dropped.
242+ # https://github.com/googleapis/python-api-core/issues/594
243+ if install_grpc_gcp :
244+ constraints_path = str (
245+ CURRENT_DIRECTORY / "testing" / f"constraints-{ session .python } .txt"
246+ )
247+ # Install grpcio-gcp
248+ session .install ("-e" , ".[grpcgcp]" , "-c" , constraints_path )
249+ # Install protobuf < 4.0.0
250+ session .install ("protobuf<4.0.0" )
251+
252+ default (
253+ session = session ,
254+ install_grpc = install_grpc ,
255+ install_async_rest = install_async_rest ,
239256 )
240- # Install grpcio-gcp
241- session .install ("-e" , ".[grpcgcp]" , "-c" , constraints_path )
242- # Install protobuf < 4.0.0
243- session .install ("protobuf<4.0.0" )
244-
245- default (session )
246257
247258
248259@nox .session (python = PYTHON_VERSIONS )
249- def unit_wo_grpc (session ):
250- """Run the unit test suite w/o grpcio installed"""
251- default (session , install_grpc = False )
252-
253-
254- @nox .session (python = PYTHON_VERSIONS )
255- def unit_w_async_rest_extra (session ):
256- """Run the unit test suite with the `async_rest` extra"""
257- default (session , install_async_rest = True )
260+ def prerelease_deps (session ):
261+ """Run the unit test suite."""
262+ default (session , prerelease = True )
258263
259264
260265@nox .session (python = DEFAULT_PYTHON_VERSION )
@@ -265,27 +270,6 @@ def lint_setup_py(session):
265270 session .run ("python" , "setup.py" , "check" , "--restructuredtext" , "--strict" )
266271
267272
268- @nox .session (python = DEFAULT_PYTHON_VERSION )
269- def pytype (session ):
270- """Run type-checking."""
271- session .install (".[grpc]" , "pytype" )
272- session .run ("pytype" )
273-
274-
275- @nox .session (python = DEFAULT_PYTHON_VERSION )
276- def mypy (session ):
277- """Run type-checking."""
278- session .install (".[grpc,async_rest]" , "mypy" )
279- session .install (
280- "types-setuptools" ,
281- "types-requests" ,
282- "types-protobuf" ,
283- "types-dataclasses" ,
284- "types-mock; python_version=='3.7'" ,
285- )
286- session .run ("mypy" , "google" , "tests" )
287-
288-
289273@nox .session (python = DEFAULT_PYTHON_VERSION )
290274def cover (session ):
291275 """Run the final coverage report.
0 commit comments