From 7f9f33be1c9d89f203613e9d1a54ad2767d1458a Mon Sep 17 00:00:00 2001 From: Adam Dangoor Date: Thu, 18 Sep 2025 12:47:27 +0100 Subject: [PATCH 1/2] Use incorrect type for a pytest fixture to demonstrate beartype catching the error --- tests/test_vws.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_vws.py b/tests/test_vws.py index e16eff55..5f8e9ea9 100644 --- a/tests/test_vws.py +++ b/tests/test_vws.py @@ -36,7 +36,7 @@ class TestAddTarget: ) @pytest.mark.parametrize(argnames="active_flag", argvalues=[True, False]) def test_add_target( - vws_client: VWS, + vws_client: int, image: io.BytesIO | BinaryIO, application_metadata: bytes | None, cloud_reco_client: CloudRecoService, From 34c7fdc3abbee8343c9bc8913e02980058fab6c3 Mon Sep 17 00:00:00 2001 From: Adam Dangoor Date: Thu, 18 Sep 2025 13:02:54 +0100 Subject: [PATCH 2/2] Use pytest-beartype rather than decorating test functions --- conftest.py | 10 ---------- pyproject.toml | 2 ++ 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/conftest.py b/conftest.py index 1d776f8d..15b489ec 100644 --- a/conftest.py +++ b/conftest.py @@ -9,7 +9,6 @@ from pathlib import Path import pytest -from beartype import beartype from mock_vws import MockVWS from mock_vws.database import VuforiaDatabase from sybil import Sybil @@ -20,15 +19,6 @@ ) -def pytest_collection_modifyitems(items: list[pytest.Item]) -> None: - """ - Apply the beartype decorator to all collected test functions. - """ - for item in items: - if isinstance(item, pytest.Function): - item.obj = beartype(obj=item.obj) - - @pytest.fixture(name="make_image_file") def fixture_make_image_file( high_quality_image: io.BytesIO, diff --git a/pyproject.toml b/pyproject.toml index d3d24c83..58cbd5f5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -57,6 +57,7 @@ optional-dependencies.dev = [ "pyright==1.1.405", "pyroma==5.0", "pytest==8.4.2", + "pytest-beartype>=0.2.0", "pytest-cov==7.0.0", "pyyaml==6.0.2", "ruff==0.13.0", @@ -316,6 +317,7 @@ max_supported_python = "3.13" xfail_strict = true log_cli = true +addopts = "--beartype-packages=tests" [tool.coverage.run]