Skip to content

Commit 0127db9

Browse files
Add runtime type checking in CI tests
This should prevent TYPE_CHECKING misuse. It might also found issues not found by static type checking, typically by the current MyPy.
1 parent 876b73a commit 0127db9

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

.github/workflows/ci-additional.yaml

+40
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,46 @@ jobs:
8282
# `xarray/tests/__init__.py`.
8383
python -m pytest --doctest-modules xarray --ignore xarray/tests -Werror
8484
85+
beartype:
86+
name: beartype
87+
runs-on: "ubuntu-latest"
88+
needs: detect-ci-trigger
89+
defaults:
90+
run:
91+
shell: bash -l {0}
92+
env:
93+
CONDA_ENV_FILE: ci/requirements/environment.yml
94+
PYTHON_VERSION: "3.12"
95+
96+
steps:
97+
- uses: actions/checkout@v4
98+
with:
99+
fetch-depth: 0 # Fetch all history for all branches and tags.
100+
101+
- name: set environment variables
102+
run: |
103+
echo "TODAY=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
104+
- name: Setup micromamba
105+
uses: mamba-org/setup-micromamba@v2
106+
with:
107+
micromamba-version: ${{env.MICROMAMBA_VERSION}}
108+
environment-file: ${{env.CONDA_ENV_FILE}}
109+
environment-name: xarray-tests
110+
create-args: >-
111+
python=${{env.PYTHON_VERSION}}
112+
cache-environment: true
113+
cache-environment-key: "${{runner.os}}-${{runner.arch}}-py${{env.PYTHON_VERSION}}-${{env.TODAY}}-${{hashFiles(env.CONDA_ENV_FILE)}}"
114+
- name: Install xarray
115+
run: |
116+
python -m pip install --no-deps -e .
117+
- name: Version info
118+
run: |
119+
python xarray/util/print_versions.py
120+
121+
- name: Run beartype
122+
run: |
123+
python -m pytest --beartype-packages=xarray
124+
85125
mypy:
86126
name: Mypy
87127
runs-on: "ubuntu-latest"

ci/requirements/environment.yml

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ dependencies:
3838
- pydap
3939
- pydap-server
4040
- pytest
41+
- pytest-beartype
4142
- pytest-cov
4243
- pytest-env
4344
- pytest-xdist

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ dev = [
4141
"mypy",
4242
"pre-commit",
4343
"pytest",
44+
"pytest-beartype",
4445
"pytest-cov",
4546
"pytest-env",
4647
"pytest-xdist",

0 commit comments

Comments
 (0)