Skip to content

Commit 30ffbd8

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

File tree

4 files changed

+75
-160
lines changed

4 files changed

+75
-160
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: 42 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,8 @@
3636
# 'docfx' is excluded since it only needs to run in 'docs-presubmit'
3737
nox.options.sessions = [
3838
"unit",
39-
"unit_grpc_gcp",
40-
"unit_wo_grpc",
41-
"unit_w_prerelease_deps",
42-
"unit_w_async_rest_extra",
39+
"prerelease_deps",
4340
"cover",
44-
"pytype",
45-
"mypy",
4641
"lint",
4742
"lint_setup_py",
4843
"blacken",
@@ -70,6 +65,17 @@ def lint(session):
7065
)
7166
session.run("flake8", "google", "tests")
7267

68+
"""Run type-checking."""
69+
session.install(".[grpc,async_rest]", "mypy")
70+
session.install(
71+
"types-setuptools",
72+
"types-requests",
73+
"types-protobuf",
74+
"types-dataclasses",
75+
"types-mock; python_version=='3.7'",
76+
)
77+
session.run("mypy", "google", "tests")
78+
7379

7480
@nox.session(python=DEFAULT_PYTHON_VERSION)
7581
def blacken(session):
@@ -215,46 +221,41 @@ def default(session, install_grpc=True, prerelease=False, install_async_rest=Fal
215221

216222

217223
@nox.session(python=PYTHON_VERSIONS)
218-
def unit(session):
224+
@nox.parametrize(
225+
["install_grpc_gcp", "install_grpc", "install_async_rest"],
226+
[
227+
(False, True, False), # Run unit tests with grpcio installed
228+
(True, True, False), # Run unit tests with grpcio/grpcio-gcp installed
229+
(False, False, False), # Run unit tests without grpcio installed
230+
(False, True, True), # Run unit tests with grpcio and async rest installed
231+
],
232+
)
233+
def unit(session, install_grpc_gcp, install_grpc, install_async_rest):
219234
"""Run the unit test suite."""
220-
default(session)
221-
222235

223-
@nox.session(python=PYTHON_VERSIONS)
224-
def unit_w_prerelease_deps(session):
225-
"""Run the unit test suite."""
226-
default(session, prerelease=True)
227-
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"
236+
# `grpcio-gcp` doesn't support protobuf 4+.
237+
# Remove extra `grpcgcp` when protobuf 3.x is dropped.
238+
# https://github.com/googleapis/python-api-core/issues/594
239+
if install_grpc_gcp:
240+
constraints_path = str(
241+
CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt"
242+
)
243+
# Install grpcio-gcp
244+
session.install("-e", ".[grpcgcp]", "-c", constraints_path)
245+
# Install protobuf < 4.0.0
246+
session.install("protobuf<4.0.0")
247+
248+
default(
249+
session=session,
250+
install_grpc=install_grpc,
251+
install_async_rest=install_async_rest,
239252
)
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)
246-
247-
248-
@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)
252253

253254

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)
255+
@nox.session(python=DEFAULT_PYTHON_VERSION)
256+
def prerelease_deps(session):
257+
"""Run the unit test suite."""
258+
default(session, prerelease=True)
258259

259260

260261
@nox.session(python=DEFAULT_PYTHON_VERSION)
@@ -265,27 +266,6 @@ def lint_setup_py(session):
265266
session.run("python", "setup.py", "check", "--restructuredtext", "--strict")
266267

267268

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-
289269
@nox.session(python=DEFAULT_PYTHON_VERSION)
290270
def cover(session):
291271
"""Run the final coverage report.

0 commit comments

Comments
 (0)