python data_error ai_generated true

Skipped: got empty parameter set for (u)<function test_parse at 0x7f...>

ID: python/pytest-parametrize-empty

Also available as: JSON · Markdown · 中文
80%Fix Rate
83%Confidence
0Evidence
2024-08-19First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
7.x active — — —
8.x active — — —

Root Cause

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

中文

`@pytest.mark.parametrize` 装饰器接收到空列表,pytest 因此跳过该测试。常见原因是 fixture 或生成器返回空集合。

Workarounds

  1. 90% success
    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% success
    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)

Dead Ends

Common approaches that don't work:

  1. 75% fail

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

  2. 65% fail

    Makes the test always skipped, losing coverage silently.