"""Tests for the pytest plugin hooks.""" import pytest @pytest.fixture def plugin_pytester(pytester: pytest.Pytester) -> pytest.Pytester: return pytester def test_plugin_registers_marker(plugin_pytester: pytest.Pytester) -> None: 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: 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: 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: 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: 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*"])