test_lazy_choices_help fails on Python 3.14
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 52/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 停滞
- 技术栈
- python
- 领域
- cli, testing-qa
调研方向
从 tests/test_cli_utils.py::test_lazy_choices_help 开始,使用 Python 3.14 和列出的 uv 命令复现该失败。跟踪 ArgumentParser 和 LazyChoices 的初始化过程,找出 getter 为何会被过早调用,然后在不改变其预期 lazy 行为的情况下让测试通过。
由索引模型根据 Issue 内容生成。
描述
Checklist
- I've searched for similar issues.
- I'm using the latest version of HTTPie (from git HEAD)
Minimal reproduction code and steps
This is with Python 3.14.0b3 and b4 alike.
uv venv --python=python3.14 venv
. venv/bin/activate
uv pip install '.[dev]'
uv pip install -U httpbin flask werkzeug # to support Python 3.14
python -m pytest --verbose -k test_lazy_choices_help
Current result
============================= test session starts ==============================
platform linux -- Python 3.14.0b3, pytest-8.4.1, pluggy-1.6.0 -- .../httpie/venv/bin/python
cachedir: .pytest_cache
rootdir: .../httpie
configfile: pytest.ini
plugins: mock-3.14.1, httpbin-2.1.0, cov-6.2.1
collecting ... collected 1028 items / 1027 deselected / 1 selected
tests/test_cli_utils.py::test_lazy_choices_help FAILED [100%]
=================================== FAILURES ===================================
____________________________ test_lazy_choices_help ____________________________
self = <Mock name='mock.getter' id='140611738470112'>
def assert_not_called(self):
"""assert that the mock was never called.
"""
if self.call_count != 0:
msg = ("Expected '%s' to not have been called. Called %s times.%s"
% (self._mock_name or 'mock',
self.call_count,
self._calls_repr()))
> raise AssertionError(msg)
E AssertionError: Expected 'getter' to not have been called. Called 1 times.
E Calls: [call()].
/usr/lib64/python3.14/unittest/mock.py:946: AssertionError
During handling of the above exception, another exception occurred:
def test_lazy_choices_help():
mock = Mock()
getter = mock.getter
getter.return_value = ['a', 'b', 'c']
help_formatter = mock.help_formatter
help_formatter.return_value = '<my help>'
parser = ArgumentParser()
parser.register('action', 'lazy_choices', LazyChoices)
parser.add_argument(
'--lazy-option',
default='a',
metavar='SYMBOL',
action='lazy_choices',
getter=getter,
help_formatter=help_formatter,
cache=False # for test purposes
)
# Parser initialization doesn't call it.
> getter.assert_not_called()
E AssertionError: Expected 'getter' to not have been called. Called 1 times.
E Calls: [call()].
tests/test_cli_utils.py:73: AssertionError
=============================== warnings summary ===============================
httpie/cli/definition.py:526
.../httpie/httpie/cli/definition.py:526: PendingDeprecationWarning: FileType is deprecated. Simply open files after parsing arguments.
type=FileType('a+b'),
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=========================== short test summary info ============================
FAILED tests/test_cli_utils.py::test_lazy_choices_help - AssertionError: Expe...
================ 1 failed, 1027 deselected, 1 warning in 0.20s =================
Expected result
Tests pass.
- 主要语言
- Python
- 星标
- 38.6k
- 派生
- 4k
- PR 合并指标
- 30 天内没有已合并 PR
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
httpie/cli 的其他 Issue
-
new
难度 2/5 1-3 小时 新手友好度 70/100
-
难度 2/5 1-3 小时 新手友好度 78/100
-
bug new
难度 4/5 3-5 天 新手友好度 48/100
-
难度 3/5 1-2 天 新手友好度 55/100
-
难度 4/5 3-5 天 新手友好度 35/100
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 75/100
-
hcocena 未关闭policies-accepted pre-review precheck-passed
难度 1/5 1 小时以内 新手友好度 88/100
Bioconductor/BiocContributions#214 · 5 条评论 ·
-
难度 1/5 1 小时以内 新手友好度 92/100
TencentCloud/Octop#1169 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 70/100
521xueweihan/HelloGitHub#3778 ·
-
The version checker's trailing attribute region has no control for a less-than inside a quoted value 未关闭area: dashboard area: tests bug perceived difficulty: 2 python
难度 2/5 1-3 小时 新手友好度 84/100
Nitjsefnie-Harness-Commons/daedalus#1105 · 1 条评论 ·