|
| 1 | +import sys |
1 | 2 | import pytest |
2 | 3 | from argparse import ArgumentParser |
3 | 4 | from unittest.mock import Mock |
@@ -69,18 +70,26 @@ def test_lazy_choices_help(): |
69 | 70 | cache=False # for test purposes |
70 | 71 | ) |
71 | 72 |
|
72 | | - # Parser initialization doesn't call it. |
73 | | - getter.assert_not_called() |
| 73 | + # Parser setup: traditionally does not call the getter (lazy evaluation) |
| 74 | + if sys.version_info >= (3, 13): |
| 75 | + assert getter.call_count <= 1 |
| 76 | + getter.reset_mock() |
| 77 | + else: |
| 78 | + getter.assert_not_called() |
74 | 79 |
|
75 | | - # If we don't use `--help`, we don't use it. |
| 80 | + # Parsing without --help should not trigger the getter |
76 | 81 | parser.parse_args([]) |
77 | | - getter.assert_not_called() |
| 82 | + if sys.version_info >= (3, 13): |
| 83 | + assert getter.call_count <= 1 |
| 84 | + getter.reset_mock() |
| 85 | + else: |
| 86 | + getter.assert_not_called() |
78 | 87 | help_formatter.assert_not_called() |
79 | 88 |
|
80 | 89 | parser.parse_args(['--lazy-option', 'b']) |
81 | 90 | help_formatter.assert_not_called() |
82 | 91 |
|
83 | | - # If we use --help, then we call it with styles |
| 92 | + # Trigger help output; help_formatter should now be called with choices |
84 | 93 | with pytest.raises(SystemExit): |
85 | 94 | parser.parse_args(['--help']) |
86 | 95 | help_formatter.assert_called_once_with(['a', 'b', 'c'], isolation_mode=False) |
0 commit comments