Repository navigation
|
I have a value parameterized test with a long list of test params:
@dataclass(frozen=True):
class TestInput
a: str
# 10+ more fields
@dataclass(frozen=True):
class TestParam
a: str
# 5 more fields
@dataclass(frozen=True):
class TestWant
a: str
# 5 more fields
@pytest.mark.parametrize(
"input,param,want",
(
pytest.param(
TestInput(
# 10+ args, one per line
),
TestParam(
# ~5 args, one per line
),
TestWant(
# ~5 args, one per line
),
id = "first test case"
),
# more test cases follow
)
def test_foo(input, param, want):
...Pytest prints the failed test case's params upon error along with the Is there a way to reduce the output of a failed test to
? DemoThe demonstration includes comments in the test params - these should be output as well upon failure. # file: ./param_test.py
import pytest
@pytest.mark.parametrize(
"input,want",
(
# the parameters might be very long, spanning multiple lines
pytest.param(1, 1, id="demo test passes"),
# for example, the params might be dataclasses, e.g. TestInput and
# TestWant.
pytest.param(2, 3, id="demo test fails"),
# more test data
pytest.param(4, 4, id="demo test passes again"),
),
)
def test_demo(input, want):
assert input == wantrun: want: |
Answered by
g4lb
Nov 8, 2026
Replies: 1 comment 2 replies
|
pytest prints the test source from the decorator. Move the cases to a variable, and the failure shows one decorator line, the body, and the failing values: @pytest.mark.parametrize("input,want", CASES) |
2 replies
Answer selected by
skhal
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
pytest prints the test source from the decorator. Move the cases to a variable, and the failure shows one decorator line, the body, and the failing values:
@pytest.mark.parametrize("input,want", CASES)