-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed as duplicate of#13031
Closed as duplicate of#13031
Copy link
Description
Steps to Reproduce:
- Create a pytest fixture with an empty
paramslist and anidsfunction that references an attribute of the param, e.g.:
@pytest.fixture(params=[], ids=lambda x: x.id)
def empty_param(request):
return request.param2.Write a test function that uses this fixture:
def test_empty_param(empty_param):
pass3.Run the test using the pytest command:
pytest test_foo.py::test_empty_param
Expected Behavior:
The test should either be skipped or provide a more informative error message indicating that the params list is empty.
Actual Behavior:
The test raises an AttributeError: 'NotSetType' object has no attribute 'id' error.
Error Output
tests/test_foo.py:None (tests/test_foo.py)
test_foo.py:163: in <lambda>
@pytest.fixture(params=[], ids=lambda x: x.id)
E AttributeError: 'NotSetType' object has no attribute 'id'
The above exception was the direct cause of the following exception:
../venv/lib/python3.12/site-packages/pluggy/_hooks.py:513: in __call__
return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
...
E ValueError: tests/test_foo.py::test_empty_param: error raised while trying to determine id of parameter 'empty_param' at position 0
collected 0 items / 1 error
Environment:
pytest version: 8.3.4
Python version: 3.12
Operating System: macOS
Possible Solution:
Provide a more informative error message or skip the test when the params list is empty. Alternatively, document the expected behavior when using an empty params list with a custom ids function.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels