Skip to content

Commit 25c2bc4

Browse files
tests: fix test_lazy_choices_help for Python 3.13+ (Fixes #1641)
1 parent 5b604c3 commit 25c2bc4

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

tests/test_cli_utils.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import sys
12
import pytest
23
from argparse import ArgumentParser
34
from unittest.mock import Mock
@@ -69,18 +70,26 @@ def test_lazy_choices_help():
6970
cache=False # for test purposes
7071
)
7172

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()
7479

75-
# If we don't use `--help`, we don't use it.
80+
# Parsing without --help should not trigger the getter
7681
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()
7887
help_formatter.assert_not_called()
7988

8089
parser.parse_args(['--lazy-option', 'b'])
8190
help_formatter.assert_not_called()
8291

83-
# If we use --help, then we call it with styles
92+
# Trigger help output; help_formatter should now be called with choices
8493
with pytest.raises(SystemExit):
8594
parser.parse_args(['--help'])
8695
help_formatter.assert_called_once_with(['a', 'b', 'c'], isolation_mode=False)

0 commit comments

Comments
 (0)