Skip to content

Parametrizing a test with an empty list calls ids callback with the private constant NOTSET #13031

@mon

Description

@mon

I parametrize tests based on a user-provided list. Sometimes this list is empty, which disables some tests as a result. However, I would expect the ids callback that I provide to not be called at all in that case, but it is actually called with the private NOTSET sentinel. As this is not exported, I can't easily check for it in my ids function and return a useless value to match it.

Reproduction:

conftest.py

import logging

def idmap(obj):
    logging.info(obj)

def pytest_generate_tests(metafunc):
    if "arg" in metafunc.fixturenames:
        metafunc.parametrize(
            "arg", [], ids=idmap
        )

test_demo.py

def test_demo(arg):
    pass
$: pytest --collect-only --log-cli-level=DEBUG
...
INFO     root:conftest.py:4 NotSetType.token
...

Python: 3.10.15
pytest: 8.3.4
OS: macOS Sonoma 14.6.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions