Skip to content

Commit

Permalink
Add runtime type checking in CI tests
Browse files Browse the repository at this point in the history
This should prevent TYPE_CHECKING misuse.

It might also found issues not found by static type checking,
typically by the current MyPy.
  • Loading branch information
DimitriPapadopoulos committed Nov 7, 2024
1 parent c65b8a6 commit 6891361
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/ci-additional.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,46 @@ jobs:
# `xarray/tests/__init__.py`.
python -m pytest --doctest-modules xarray --ignore xarray/tests -Werror
beartype:
name: beartype
runs-on: "ubuntu-latest"
needs: detect-ci-trigger
defaults:
run:
shell: bash -l {0}
env:
CONDA_ENV_FILE: ci/requirements/environment.yml
PYTHON_VERSION: "3.12"

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for all branches and tags.

- name: set environment variables
run: |
echo "TODAY=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
- name: Setup micromamba
uses: mamba-org/setup-micromamba@v2
with:
micromamba-version: ${{env.MICROMAMBA_VERSION}}
environment-file: ${{env.CONDA_ENV_FILE}}
environment-name: xarray-tests
create-args: >-
python=${{env.PYTHON_VERSION}}
cache-environment: true
cache-environment-key: "${{runner.os}}-${{runner.arch}}-py${{env.PYTHON_VERSION}}-${{env.TODAY}}-${{hashFiles(env.CONDA_ENV_FILE)}}"
- name: Install xarray
run: |
python -m pip install --no-deps -e .
- name: Version info
run: |
python xarray/util/print_versions.py
- name: Run beartype
run: |
python -m pytest --beartype-packages=xarray
mypy:
name: Mypy
runs-on: "ubuntu-latest"
Expand Down
1 change: 1 addition & 0 deletions ci/requirements/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ dependencies:
- beautifulsoup4
# end pydap server dependencies
- pytest
- pytest-beartype
- pytest-cov
- pytest-env
- pytest-xdist
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ dev = [
"mypy",
"pre-commit",
"pytest",
"pytest-beartype",
"pytest-cov",
"pytest-env",
"pytest-xdist",
Expand Down

0 comments on commit 6891361

Please sign in to comment.