python
data_error
ai_generated
true
Skipped: got empty parameter set for (u)<function test_parse at 0x7f...>
ID: python/pytest-parametrize-empty
80%Fix Rate
83%Confidence
0Evidence
2024-08-19First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 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
-
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): ... -
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:
-
75% fail
IDs don't create test cases; the parameter list is still empty.
-
65% fail
Makes the test always skipped, losing coverage silently.