Coverage for tests / unit / tools / pytest_tool / test_validators.py: 100%

17 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2026-04-03 18:53 +0000

1"""Tests for pytest option validation functions.""" 

2 

3from __future__ import annotations 

4 

5import pytest 

6 

7from lintro.tools.implementations.pytest.pytest_option_validators import ( 

8 validate_pytest_options, 

9) 

10 

11# ============================================================================= 

12# Tests for pytest option validation functions 

13# ============================================================================= 

14 

15 

16def test_validate_valid_options_passes() -> None: 

17 """Valid options pass validation without error.""" 

18 # Should not raise - test passes if no exception 

19 validate_pytest_options( 

20 verbose=True, 

21 tb="short", 

22 maxfail=5, 

23 junitxml="report.xml", 

24 ) 

25 

26 

27def test_validate_invalid_tb_raises() -> None: 

28 """Invalid tb value raises ValueError.""" 

29 with pytest.raises(ValueError, match="tb must be one of"): 

30 validate_pytest_options(tb="invalid") 

31 

32 

33def test_validate_invalid_maxfail_raises() -> None: 

34 """Invalid maxfail value raises ValueError.""" 

35 with pytest.raises(ValueError, match="maxfail must be a positive integer"): 

36 validate_pytest_options(maxfail=-1) 

37 

38 

39def test_validate_invalid_coverage_threshold_raises() -> None: 

40 """Invalid coverage_threshold raises ValueError.""" 

41 with pytest.raises(ValueError, match="coverage_threshold must be between"): 

42 validate_pytest_options(coverage_threshold=101) 

43 

44 

45def test_validate_flaky_failure_rate_bounds() -> None: 

46 """Flaky failure rate must be between 0 and 1.""" 

47 with pytest.raises(ValueError, match="flaky_failure_rate must be between"): 

48 validate_pytest_options(flaky_failure_rate=1.5)