Skip to content

Commit 5a88160

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. Make it optional for now, while we fix issues.
1 parent 1622499 commit 5a88160

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

.github/workflows/ci-additional.yaml

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