Check the type annotations at runtime with typeguard
This commit is contained in:
parent
893b6bd8f1
commit
5f7d3108de
1 changed files with 63 additions and 0 deletions
35
noxfile.py
35
noxfile.py
|
|
@ -6,6 +6,7 @@ By default, `uv run nox` runs the sessions that assure code quality:
|
|||
- "lint": Lint source files with `flake8`, `isort`, `mypy`, `pyright`, and `ruff`
|
||||
- "test": Run the test suite with `pytest`
|
||||
- "doctest": Check if code snippets in the docstrings run
|
||||
- "test-types": Run the test suite with runtime type checks by `typeguard`
|
||||
|
||||
Further sessions run on demand with `uv run nox -s <session>`:
|
||||
|
||||
|
|
@ -139,6 +140,7 @@ nox.options.sessions = (
|
|||
"lint",
|
||||
"test",
|
||||
"doctest",
|
||||
"test-types",
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -327,6 +329,39 @@ def test_docstrings(session: nox.Session) -> None:
|
|||
)
|
||||
|
||||
|
||||
@nox.session(name="test-types", python=MAIN_PYTHON)
|
||||
def test_types(session: nox.Session) -> None:
|
||||
"""Check the type annotations at runtime with `typeguard`.
|
||||
|
||||
This runs the entire `pytest` suite.
|
||||
|
||||
Unlike the "test" session, no coverage is measured
|
||||
because the instrumentation of `typeguard` distorts the branch coverage.
|
||||
|
||||
Extra arguments are forwarded to `pytest`.
|
||||
"""
|
||||
start(session)
|
||||
|
||||
install_pinned(
|
||||
session,
|
||||
".",
|
||||
"factory-boy",
|
||||
"Faker",
|
||||
"packaging",
|
||||
"pytest",
|
||||
"pytest-cov",
|
||||
"pytest-env",
|
||||
"pytest-mock",
|
||||
"typeguard",
|
||||
)
|
||||
|
||||
# Make tests/__init__.py install the import hook for `typeguard`
|
||||
session.env["TYPEGUARD"] = "true"
|
||||
|
||||
session.run("pytest", "--version")
|
||||
session.run("pytest", *(session.posargs or (TESTS_LOCATION,)))
|
||||
|
||||
|
||||
@nox.session(name="docs", python=MAIN_PYTHON)
|
||||
def build_docs(session: nox.Session) -> None:
|
||||
"""Build the documentation with `sphinx`.
|
||||
|
|
|
|||
Loading…
Reference in a new issue