-
Notifications
You must be signed in to change notification settings - Fork 25
Collapse repetitive endpoint tests with @pytest.mark.parametrize #643
Copy link
Copy link
Open
Labels
enhancementNew feature or requestNew feature or requestpriority:lowNice-to-have improvement. Can be deferred without blocking other work.Nice-to-have improvement. Can be deferred without blocking other work.pythonPull requests that update Python codePull requests that update Python codepython:idiomsRefactors toward idiomatic Python (PEP conventions, stdlib idioms)Refactors toward idiomatic Python (PEP conventions, stdlib idioms)
Description
Activity
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestpriority:lowNice-to-have improvement. Can be deferred without blocking other work.Nice-to-have improvement. Can be deferred without blocking other work.pythonPull requests that update Python codePull requests that update Python codepython:idiomsRefactors toward idiomatic Python (PEP conventions, stdlib idioms)Refactors toward idiomatic Python (PEP conventions, stdlib idioms)
Problem
tests/test_main.pyhas many near-identical test functions that differ only inan input value and an expected status code — the "returns 404" cases for GET by
id, GET by squad number, PUT, and DELETE each repeat the same
arrange/act/assert shape; the cache-header and empty-body cases likewise. This
is the xUnit "one method per case" style. pytest provides a table-driven idiom.
Proposed Solution
Group cases that share a body under
@pytest.mark.parametrize:Keep cases with bespoke setup/teardown (POST/PUT that create or mutate rows) as
their own functions — parametrising those hurts readability.
Suggested Approach
pair (
MISSthenHIT), the 422 empty-body pair.ids=sofailures name the case.
tests/test_main.pyis excluded from Black — match the existing manualformatting.
Acceptance Criteria
parametrizeidCHANGELOG.mdupdatedReferences