move root conftest into pytest plugins

This commit is contained in:
2026-07-16 16:30:38 +03:00
parent bfd3148617
commit 14dd97f2ca
6 changed files with 42 additions and 9 deletions
-4
View File
@@ -1,9 +1,5 @@
[pytest] [pytest]
addopts = [ addopts = [
"--cov=ahriman",
"--cov-report=term-missing:skip-covered",
"--no-cov-on-fail",
"--cov-fail-under=100",
"--spec", "--spec",
] ]
asyncio_default_fixture_loop_scope = "function" asyncio_default_fixture_loop_scope = "function"
+1 -1
View File
@@ -44,9 +44,9 @@ docs = [
"sphinx-rtd-theme>=1.1.1", # https://stackoverflow.com/a/74355734 "sphinx-rtd-theme>=1.1.1", # https://stackoverflow.com/a/74355734
] ]
tests = [ tests = [
"coverage",
"pytest", "pytest",
"pytest-aiohttp", "pytest-aiohttp",
"pytest-cov",
"pytest-helpers-namespace", "pytest-helpers-namespace",
"pytest-mock", "pytest-mock",
"pytest-resource-path", "pytest-resource-path",
+1
View File
@@ -0,0 +1 @@
"""Repository-local pytest plugins."""
@@ -41,7 +41,6 @@ T = TypeVar("T")
# helpers # helpers
# https://stackoverflow.com/a/21611963 # https://stackoverflow.com/a/21611963
@pytest.helpers.register
def anyvar(cls: type[T], strict: bool = False) -> T: def anyvar(cls: type[T], strict: bool = False) -> T:
""" """
any value helper for mocker calls check any value helper for mocker calls check
@@ -73,7 +72,6 @@ def anyvar(cls: type[T], strict: bool = False) -> T:
return AnyVar() return AnyVar()
@pytest.helpers.register
def get_package_status(package: Package) -> dict[str, Any]: def get_package_status(package: Package) -> dict[str, Any]:
""" """
helper to extract package status from package 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()} return {"status": BuildStatusEnum.Unknown.value, "package": package.view()}
@pytest.helpers.register
def get_package_status_extended(package: Package) -> dict[str, Any]: def get_package_status_extended(package: Package) -> dict[str, Any]:
""" """
helper to extract package status from package 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()} return {"status": BuildStatus().view(), "package": package.view()}
@pytest.helpers.register
def import_error(package: str, components: list[str], mocker: MockerFixture) -> MagicMock: def import_error(package: str, components: list[str], mocker: MockerFixture) -> MagicMock:
""" """
mock import error 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) 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 # generic fixtures
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def register_log_context() -> None: def register_log_context() -> None:
+18
View File
@@ -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 = ["."]
+13
View File
@@ -335,11 +335,17 @@ dependency_groups = [
] ]
deps = [ deps = [
{ replace = "ref", of = ["project", "extras"], extend = true }, { replace = "ref", of = ["project", "extras"], extend = true },
"./tools/pytest_plugins",
] ]
pip_pre = true pip_pre = true
set_env.CFLAGS = "-Wno-unterminated-string-initialization" set_env.CFLAGS = "-Wno-unterminated-string-initialization"
commands = [ commands = [
[ [
"coverage",
"run",
"--source",
"ahriman",
"-m",
"pytest", "pytest",
"tests/test_tests.py", "tests/test_tests.py",
"ahriman-core/tests", "ahriman-core/tests",
@@ -347,6 +353,13 @@ commands = [
"ahriman-web/tests", "ahriman-web/tests",
{ replace = "posargs", extend = true }, { replace = "posargs", extend = true },
], ],
[
"coverage",
"report",
"--show-missing",
"--skip-covered",
"--fail-under=100",
],
] ]
[env.version] [env.version]