python
data_error
ai_generated
true
已跳过: (u)<function test_parse at 0x7f...> 的参数集为空
Skipped: got empty parameter set for (u)<function test_parse at 0x7f...>
ID: python/pytest-parametrize-empty
80%修复率
83%置信度
0证据数
2024-08-19首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 7.x | active | — | — | — |
| 8.x | active | — | — | — |
根因分析
`@pytest.mark.parametrize` 装饰器接收到空列表,pytest 因此跳过该测试。常见原因是 fixture 或生成器返回空集合。
English
A `@pytest.mark.parametrize` decorator was given an empty list, so pytest skips the test. Often caused by a fixture or generator returning an empty collection.
解决方案
-
90% 成功率
Ensure the parametrize list is non-empty: CASES = load_cases() assert CASES, 'no cases loaded' @pytest.mark.parametrize('u', CASES) def test_parse(u): ... -
85% 成功率
Use `pytest_generate_tests` to dynamically parametrize with a guard: def pytest_generate_tests(metafunc): if 'u' in metafunc.fixturenames: cases = load_cases() or [pytest.param(None, marks=pytest.mark.skip('no cases'))] metafunc.parametrize('u', cases)
无效尝试
常见但无效的做法:
-
75% 失败
IDs don't create test cases; the parameter list is still empty.
-
65% 失败
Makes the test always skipped, losing coverage silently.