Cover validate_text assertions, fixture factories, marker registration, and pytest integration using pytester for subprocess testing.
101 lines
2.8 KiB
Python
101 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."""
|
|
pytester.makeconftest(
|
|
"""
|
|
pytest_plugins = ['veritext.pytest_plugin']
|
|
"""
|
|
)
|
|
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*"])
|