Files
veritext/tests/test_pytest_plugin/test_plugin.py
Kai Chappell 7de4505e31 fix(pytest-plugin): remove duplicate plugin registration in tests
The pytest plugin is already loaded via the entry point, so explicitly
declaring it in conftest causes a duplicate registration error.
2026-02-04 00:43:20 +00:00

100 lines
2.8 KiB
Python

"""Tests for the pytest plugin hooks."""
import pytest
@pytest.fixture
def plugin_pytester(pytester: pytest.Pytester) -> pytest.Pytester:
"""Configure pytester to use the veritext plugin.
Note: The plugin is already loaded via the entry point in pyproject.toml,
so no explicit pytest_plugins declaration is needed.
"""
return pytester
def test_plugin_registers_marker(plugin_pytester: pytest.Pytester) -> None:
"""Test that the text_validation marker is registered."""
plugin_pytester.makepyfile(
"""
import pytest
@pytest.mark.text_validation
def test_example():
pass
"""
)
# Run with strict markers - this will fail if marker isn't registered
result = plugin_pytester.runpytest("--strict-markers")
result.assert_outcomes(passed=1)
def test_marker_can_be_used(plugin_pytester: pytest.Pytester) -> None:
"""Test that the text_validation marker can filter tests."""
plugin_pytester.makepyfile(
"""
import pytest
@pytest.mark.text_validation
def test_marked():
pass
def test_unmarked():
pass
"""
)
# Run only marked tests
result = plugin_pytester.runpytest("-m", "text_validation")
result.assert_outcomes(passed=1)
def test_validate_text_is_importable(plugin_pytester: pytest.Pytester) -> None:
"""Test that validate_text can be imported from the plugin."""
plugin_pytester.makepyfile(
"""
from veritext.pytest_plugin import validate_text
def test_import():
assert callable(validate_text)
"""
)
result = plugin_pytester.runpytest()
result.assert_outcomes(passed=1)
def test_validate_text_works_in_tests(plugin_pytester: pytest.Pytester) -> None:
"""Test that validate_text can be used in test functions."""
plugin_pytester.makepyfile(
"""
from veritext.pytest_plugin import validate_text
def test_validation_passes():
validate_text(
"The quick brown fox jumps over the lazy dog.",
min_length=10,
max_length=100,
)
"""
)
result = plugin_pytester.runpytest()
result.assert_outcomes(passed=1)
def test_validate_text_failure_in_tests(plugin_pytester: pytest.Pytester) -> None:
"""Test that validate_text failures are reported properly."""
plugin_pytester.makepyfile(
"""
from veritext.pytest_plugin import validate_text
def test_validation_fails():
validate_text(
"Short",
min_length=100,
)
"""
)
result = plugin_pytester.runpytest()
result.assert_outcomes(failed=1)
# Check that failure message contains useful information
result.stdout.fnmatch_lines(["*Text validation failed*"])