python data_error ai_generated true

SKIPPED [1] tests/test_math.py:12: got empty parameter set ['a', 'b'], function test_add

ID: python/pytest-parametrize-empty-argvalues

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

Version Compatibility

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

Root Cause

`@pytest.mark.parametrize` received an empty list of values, so the test is collected but skipped. Often the data source (fixture, file, computed list) returned nothing.

generic

中文

`@pytest.mark.parametrize` 收到空的取值列表,因此测试被收集但跳过。通常是数据源(fixture、文件、计算列表)返回空。

Workarounds

  1. 90% success
    Fail fast when the data source is unexpectedly empty:
    CASES = load_cases()
    if not CASES:
        pytest.fail('no cases loaded from fixtures/cases.json')
    @pytest.mark.parametrize('a,b', CASES)
  2. 85% success
    Or use `pytest_generate_tests` to raise a clear error:
    def pytest_generate_tests(metafunc):
        if 'a' in metafunc.fixturenames:
            cases = load_cases()
            if not cases:
                pytest.fail('empty case set')
            metafunc.parametrize('a,b', cases)

Dead Ends

Common approaches that don't work:

  1. 80% fail

    Already skipped; adding skip does not surface the underlying empty-data problem, which is usually a bug.

  2. 75% fail

    Hides the real issue (data source empty) and reduces coverage silently.