diff --git a/.pytest.toml b/.pytest.toml index 927999eb..2fa361e1 100644 --- a/.pytest.toml +++ b/.pytest.toml @@ -1,9 +1,5 @@ [pytest] addopts = [ - "--cov=ahriman", - "--cov-report=term-missing:skip-covered", - "--no-cov-on-fail", - "--cov-fail-under=100", "--spec", ] asyncio_default_fixture_loop_scope = "function" diff --git a/pyproject.toml b/pyproject.toml index 6266b7e6..cb7a9ce0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -44,9 +44,9 @@ docs = [ "sphinx-rtd-theme>=1.1.1", # https://stackoverflow.com/a/74355734 ] tests = [ + "coverage", "pytest", "pytest-aiohttp", - "pytest-cov", "pytest-helpers-namespace", "pytest-mock", "pytest-resource-path", diff --git a/tools/pytest_plugins/__init__.py b/tools/pytest_plugins/__init__.py new file mode 100644 index 00000000..27574990 --- /dev/null +++ b/tools/pytest_plugins/__init__.py @@ -0,0 +1 @@ +"""Repository-local pytest plugins.""" diff --git a/conftest.py b/tools/pytest_plugins/ahriman_fixtures.py similarity index 98% rename from conftest.py rename to tools/pytest_plugins/ahriman_fixtures.py index 1c99df78..5d8542f7 100644 --- a/conftest.py +++ b/tools/pytest_plugins/ahriman_fixtures.py @@ -41,7 +41,6 @@ T = TypeVar("T") # helpers # https://stackoverflow.com/a/21611963 -@pytest.helpers.register def anyvar(cls: type[T], strict: bool = False) -> T: """ any value helper for mocker calls check @@ -73,7 +72,6 @@ def anyvar(cls: type[T], strict: bool = False) -> T: return AnyVar() -@pytest.helpers.register def get_package_status(package: Package) -> dict[str, Any]: """ helper to extract package status from package @@ -87,7 +85,6 @@ def get_package_status(package: Package) -> dict[str, Any]: return {"status": BuildStatusEnum.Unknown.value, "package": package.view()} -@pytest.helpers.register def get_package_status_extended(package: Package) -> dict[str, Any]: """ helper to extract package status from package @@ -101,7 +98,6 @@ def get_package_status_extended(package: Package) -> dict[str, Any]: return {"status": BuildStatus().view(), "package": package.view()} -@pytest.helpers.register def import_error(package: str, components: list[str], mocker: MockerFixture) -> MagicMock: """ mock import error @@ -125,6 +121,15 @@ def import_error(package: str, components: list[str], mocker: MockerFixture) -> return mocker.patch.object(builtins, "__import__", test_import) +@pytest.hookimpl(trylast=True) +def pytest_configure() -> None: + """ + register helpers after pytest-helpers-namespace has initialized + """ + for helper in (anyvar, get_package_status, get_package_status_extended, import_error): + pytest.helpers.register(helper) + + # generic fixtures @pytest.fixture(autouse=True) def register_log_context() -> None: diff --git a/tools/pytest_plugins/pyproject.toml b/tools/pytest_plugins/pyproject.toml new file mode 100644 index 00000000..c4715ae7 --- /dev/null +++ b/tools/pytest_plugins/pyproject.toml @@ -0,0 +1,18 @@ +[build-system] +requires = [ + "hatchling", +] +build-backend = "hatchling.build" + +[project] +name = "ahriman-pytest-plugins" +version = "1" +classifiers = [ + "Framework :: Pytest", +] + +[project.entry-points.pytest11] +ahriman-fixtures = "ahriman_fixtures" + +[tool.hatch.build.targets.wheel] +packages = ["."] diff --git a/tox.toml b/tox.toml index 03d8365c..35cc9ff2 100644 --- a/tox.toml +++ b/tox.toml @@ -335,11 +335,17 @@ dependency_groups = [ ] deps = [ { replace = "ref", of = ["project", "extras"], extend = true }, + "./tools/pytest_plugins", ] pip_pre = true set_env.CFLAGS = "-Wno-unterminated-string-initialization" commands = [ [ + "coverage", + "run", + "--source", + "ahriman", + "-m", "pytest", "tests/test_tests.py", "ahriman-core/tests", @@ -347,6 +353,13 @@ commands = [ "ahriman-web/tests", { replace = "posargs", extend = true }, ], + [ + "coverage", + "report", + "--show-missing", + "--skip-covered", + "--fail-under=100", + ], ] [env.version]