Skip to content

Commit 8530743

Browse files
committed
tests: consolidate presubmits
1 parent 54d1d36 commit 8530743

File tree

4 files changed

+78
-159
lines changed

4 files changed

+78
-159
lines changed

.github/sync-repo-settings.yaml

Lines changed: 0 additions & 60 deletions
This file was deleted.

.github/workflows/mypy.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.

.github/workflows/unittest.yml

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@ on:
66
- main
77

88
jobs:
9-
run-unittests:
9+
unit:
1010
name: unit${{ matrix.option }}-${{ matrix.python }}
1111
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2303): use `ubuntu-latest` once this bug is fixed.
1212
# Use ubuntu-22.04 until Python 3.7 is removed from the test matrix
1313
# https://docs.github.com/en/actions/using-github-hosted-runners/using-github-hosted-runners/about-github-hosted-runners#standard-github-hosted-runners-for-public-repositories
1414
runs-on: ubuntu-22.04
1515
strategy:
1616
matrix:
17-
option: ["", "_grpc_gcp", "_wo_grpc", "_w_prerelease_deps", "_w_async_rest_extra"]
1817
python:
1918
- "3.7"
2019
- "3.8"
@@ -24,13 +23,6 @@ jobs:
2423
- "3.12"
2524
- "3.13"
2625
- "3.14"
27-
exclude:
28-
- option: "_wo_grpc"
29-
python: 3.7
30-
- option: "_wo_grpc"
31-
python: 3.8
32-
- option: "_wo_grpc"
33-
python: 3.9
3426
steps:
3527
- name: Checkout
3628
uses: actions/checkout@v4
@@ -39,27 +31,52 @@ jobs:
3931
with:
4032
python-version: ${{ matrix.python }}
4133
allow-prereleases: true
42-
- name: Install nox
34+
- name: Install nox / pytest
4335
run: |
4436
python -m pip install --upgrade setuptools pip wheel
45-
python -m pip install nox
37+
python -m pip install nox pytest
4638
- name: Run unit tests
4739
env:
48-
COVERAGE_FILE: .coverage${{ matrix.option }}-${{matrix.python }}
40+
COVERAGE_FILE: .coverage-${{matrix.python }}
4941
run: |
50-
nox -s unit${{ matrix.option }}-${{ matrix.python }}
42+
nox -s unit-${{ matrix.python }}
5143
- name: Upload coverage results
5244
uses: actions/upload-artifact@v4
5345
with:
54-
name: coverage-artifact-${{ matrix.option }}-${{ matrix.python }}
55-
path: .coverage${{ matrix.option }}-${{ matrix.python }}
46+
name: coverage-artifact-${{ matrix.python }}
47+
path: .coverage-${{ matrix.python }}
5648
include-hidden-files: true
5749

50+
unit-prerelease:
51+
name: prerelease_deps
52+
runs-on: ubuntu-latest
53+
strategy:
54+
matrix:
55+
python: ["3.14"]
56+
option: ["prerelease"]
57+
steps:
58+
- name: Checkout
59+
uses: actions/checkout@v4
60+
- name: Setup Python
61+
uses: actions/setup-python@v5
62+
with:
63+
python-version: ${{ matrix.python }}
64+
allow-prereleases: true
65+
- name: Install nox
66+
run: |
67+
python -m pip install --upgrade setuptools pip wheel
68+
python -m pip install nox
69+
- name: Run ${{ matrix.option }} tests
70+
env:
71+
COVERAGE_FILE: .coverage${{ matrix.option }}-${{matrix.python }}
72+
run: |
73+
nox -s prerelease_deps
74+
5875
report-coverage:
5976
name: cover
6077
runs-on: ubuntu-latest
6178
needs:
62-
- run-unittests
79+
- unit
6380
steps:
6481
- name: Checkout
6582
uses: actions/checkout@v4

noxfile.py

Lines changed: 45 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from __future__ import absolute_import
1616
import os
1717
import pathlib
18+
import pytest
1819
import re
1920
import shutil
2021
import unittest
@@ -36,13 +37,8 @@
3637
# 'docfx' is excluded since it only needs to run in 'docs-presubmit'
3738
nox.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)
7585
def 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)
290274
def cover(session):
291275
"""Run the final coverage report.

0 commit comments

Comments
 (0)