Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions tests/test_cli_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
import pytest
from argparse import ArgumentParser
from unittest.mock import Mock
Expand Down Expand Up @@ -69,18 +70,26 @@ def test_lazy_choices_help():
cache=False # for test purposes
)

# Parser initialization doesn't call it.
getter.assert_not_called()
# Parser setup: traditionally does not call the getter (lazy evaluation)
if sys.version_info[:2] >= (3, 13):
assert getter.call_count <= 1
getter.reset_mock()
else:
getter.assert_not_called()

# If we don't use `--help`, we don't use it.
# Parsing without --help should not trigger the getter
parser.parse_args([])
getter.assert_not_called()
if sys.version_info[:2] >= (3, 13):
assert getter.call_count <= 1
getter.reset_mock()
else:
getter.assert_not_called()
help_formatter.assert_not_called()

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

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