Skip to content

add tests for parse_parametrize - #219

Open
Khabib73 wants to merge 2 commits into
typeddjango:masterfrom
Khabib73:fix/parse_parametrize
Open

Khabib73 wants to merge 2 commits into
typeddjango:masterfrom
Khabib73:fix/parse_parametrize

Conversation

@Khabib73

@Khabib73 Khabib73 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

I think I found a bug in the parametrize logic 🤯🤯

I wrote two test cases where we should get a ValueError, because the keys are not equal. Here is the code:

expected_keys: set[str] = set(sorted(params[0].keys()))
for idx, param in enumerate(params):
    param_keys = set(sorted(param.keys()))
    if expected_keys.intersection(param_keys) != expected_keys:

We check that the other params have the same keys, but we do not check if they have extra keys. My test cases cover this. I recently refactored the logic in this function. Before, it looked like this:

parsed_params: List[Mapping[str, Any]] = []
known_params: Optional[Set[str]] = None
for idx, param in enumerate(params):
    param_keys = set(sorted(param.keys()))
    if not known_params:
        known_params = param_keys
    elif known_params.intersection(param_keys) != known_params:
        raise ValueError(
            "All parametrized entries must have same keys."
            f'First entry is {", ".join(known_params)} but {", ".join(param_keys)} '
            "was spotted at {idx} position",
        )

The logic is the same! Please check this. Maybe I am wrong, but I am ready to fix this bug:

pytest_mypy_plugins/tests/test_logic.py:30: Failed
========================================================================================== short test summary info ==========================================================================================
FAILED pytest_mypy_plugins/tests/test_logic.py::test_parametrized_with_wrong_keys[params0] - Failed: DID NOT RAISE ValueError
FAILED pytest_mypy_plugins/tests/test_logic.py::test_parametrized_with_wrong_keys[params1] - Failed: DID NOT RAISE ValueError

Comment on lines 21 to 23
expected_keys: set[str] = set(sorted(params[0].keys()))
for idx, param in enumerate(params):
param_keys = set(sorted(param.keys()))

@Khabib73 Khabib73 Nov 16, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need really sorting?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, we don't

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants