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

其他格式: JSON · Markdown 中文 · English
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.

generic

解决方案

  1. 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): ...
  2. 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)

无效尝试

常见但无效的做法:

  1. 75% 失败

    IDs don't create test cases; the parameter list is still empty.

  2. 65% 失败

    Makes the test always skipped, losing coverage silently.