Files
Crabstero/tests/conftest.py
T
LogalDeveloper 5bbb0bbde5
Audit / Dependencies (push) Successful in 9s
CI / Formatting (push) Successful in 5s
CI / Linting (push) Successful in 4s
CI / Tests (push) Successful in 1m7s
CI / Type Checking (push) Successful in 12s
CI / Spelling (push) Successful in 8s
Expanded integration coverage and enforced test categories.
2026-06-18 16:10:40 -04:00

48 lines
1.6 KiB
Python

# Copyright 2026 Logan Fick
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Shared pytest hooks for the test suite."""
import pytest
@pytest.hookimpl(tryfirst=True)
def pytest_collection_modifyitems(
config: pytest.Config,
items: list[pytest.Item],
) -> None:
"""Apply and enforce primary test category markers by directory."""
tests_root = config.rootpath / "tests"
category_roots = (
(tests_root / "unit", pytest.mark.unit),
(tests_root / "integration", pytest.mark.integration),
)
uncategorized: list[str] = []
for item in items:
for category_root, marker in category_roots:
if item.path.is_relative_to(category_root):
item.add_marker(marker)
break
else:
uncategorized.append(str(item.path.relative_to(config.rootpath)))
if uncategorized:
formatted_paths = "\n".join(f" - {path}" for path in uncategorized)
msg = (
"Tests must live under tests/unit or tests/integration.\n"
f"Uncategorized tests:\n{formatted_paths}"
)
raise pytest.UsageError(msg)