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]
addopts = [
"--cov=ahriman",
"--cov-report=term-missing:skip-covered",
"--no-cov-on-fail",
"--cov-fail-under=100",
"--spec",
]
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
]
tests = [
"coverage",
"pytest",
"pytest-aiohttp",
"pytest-cov",
"pytest-helpers-namespace",
"pytest-mock",
"pytest-resource-path",
+1
View File
@@ -0,0 +1 @@
"""Repository-local pytest plugins."""
@@ -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:
+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 = [
{ 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]