[elbe-devel] [PATCH] tests: add typechecking test using mypy
Eduard Krein
eduard.krein at linutronix.de
Fri Jul 5 16:39:32 CEST 2024
Am 04.07.2024 um 12:09 schrieb Thomas Weißschuh:
> Python has an optional, non-enforced typesystem.
> It is useful for documentation and to avoid programming errors.
> Add a test that can be enabled on a per-module basis to validate that
> the present type-annotations are correct.
>
> Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
Reviewed-by: Eduard Krein<eduard.krein at linutronix.de>
> ---
> debian/control | 1 +
> pyproject.toml | 6 ++++++
> test/test_mypy.py | 20 ++++++++++++++++++++
> 3 files changed, 27 insertions(+)
>
> diff --git a/debian/control b/debian/control
> index 37b4f643d320..d08771691822 100644
> --- a/debian/control
> +++ b/debian/control
> @@ -28,6 +28,7 @@ Build-Depends: debhelper-compat (= 13),
> python3-guestfs,
> python3-jsonschema,
> python3-libvirt,
> + python3-mypy,
> python3-passlib,
> python3-pytest,
> python3-sphinx,
> diff --git a/pyproject.toml b/pyproject.toml
> index 10be6f04e2b0..2a5d3f952a55 100644
> --- a/pyproject.toml
> +++ b/pyproject.toml
> @@ -7,3 +7,9 @@ filename = 'docs/news/{project_date}-v{version}.rst'
>
> [tool.pytest.ini_options]
> filterwarnings = 'error'
> +
> +[tool.mypy]
> +packages = [
> + 'elbevalidate',
> +]
> +ignore_missing_imports = true
> diff --git a/test/test_mypy.py b/test/test_mypy.py
> new file mode 100644
> index 000000000000..8c91db028e48
> --- /dev/null
> +++ b/test/test_mypy.py
> @@ -0,0 +1,20 @@
> +import importlib
> +
> +import pytest
> +
> +
> + at pytest.fixture
> +def mypy_api():
> + try:
> + return importlib.import_module('mypy.api', package=__name__)
> + except ModuleNotFoundError as e:
> + if e.name == 'mypy':
> + pytest.skip(f'module {e.name} not found')
> + else:
> + raise
> +
> +
> +def test_mypy(mypy_api):
> + normal_report, error_report, exit_status = mypy_api.run([])
> + if exit_status:
> + pytest.fail(normal_report, error_report)
>
> ---
> base-commit: a9a4fd0be66f6dd9145a8a4fb5db3db510a83321
> change-id: 20240704-typecheck-ced97233654c
>
> Best regards,
--
Eduard Krein
Linutronix GmbH | Bahnhofstrasse 3 | D-88690 Uhldingen-Mühlhofen
Phone: +49 7556 25 999 19; Fax.: +49 7556 25 999 99
Hinweise zum Datenschutz finden Sie hier (Informations on data privacy
can be found here): https://linutronix.de/legal/data-protection.php
Linutronix GmbH | Firmensitz (Registered Office): Uhldingen-Mühlhofen |
Registergericht (Registration Court): Amtsgericht Freiburg i.Br.,
HRB700 806 | Geschäftsführer (Managing Directors): Heinz Egger, Thomas
Gleixner, Tiffany Silva, Sean Fennelly, Jeffrey Schneiderman
More information about the elbe-devel
mailing list