python
type_error
ai_generated
true
TypeError: test_func() missing 1 required positional argument: 'value'
ID: python/pytest-fixture-indirect-param-missing
80%Fix Rate
88%Confidence
0Evidence
2024-09-21First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 7.x | active | — | — | — |
| 8.x | active | — | — | — |
Root Cause
pytest.mark.parametrize(..., indirect=True) was used, but the named fixture does not actually accept a 'request' argument to read request.param, so the fixture returns nothing and the test sees a missing argument.
generic中文
使用了 pytest.mark.parametrize(..., indirect=True),但指定的 fixture 没有接受 'request' 参数来读取 request.param,因此 fixture 不返回内容,测试看到缺少参数。
Workarounds
-
95% success
@pytest.fixture def value(request): return request.param * 2 @pytest.mark.parametrize('value', [1, 2, 3], indirect=True) def test_func(value): assert value in (2, 4, 6) -
90% success
@pytest.fixture def make_value(): def _make(n): return n * 2 return _make @pytest.mark.parametrize('n', [1, 2, 3]) def test_func(make_value, n): assert make_value(n) in (2, 4, 6)
Dead Ends
Common approaches that don't work:
-
75% fail
Changes the fixture into a direct parameter, so the fixture logic (setup, teardown) never runs.
-
80% fail
Hides the real problem; the fixture still does not receive the parametrized value.