Skip to content

parametrize: truncate long parameters in output in -v mode, still display full value in -vv #5285

@nixjdm

Description

@nixjdm

AFAICT this ability doesn't exist.

I have a parameterized test that sometimes receives params that are long strings. I would generally prefer verbose output, but the long strings really clutter up the output pretty badly.

For example:

strings_list = [
    # Imagine several of these
    (
        """Imagine a whole paragraph here.""",
        """Imagine a whole paragraph here.""",
    ),
]

pytest.mark.parametrize(["content", "expected"], string_list)
def test_sample(content, expected):
    ....

Testing the above with pytest -v Will print the entirety of the long strings used in string_list. Normally this is just what I want, and the output for each line fits nicely on a single line, or maybe a little spill over to two. With long params though, this creates a mess that makes it more difficult to understand the total results of the test at a glance, and needs a lot more scrolling to get through.

Nonetheless, a hint to the params would be great. I suggest, to not change current behavior, the ability to decorate or otherwise mark specific tests to affect this behavior for just that test.

Alternatives:

  • A global setting to change this behavior (a good supplement)
  • Actually changing the default behavior of -v. I'd guess this isn't a welcome option.

Metadata

Metadata

Labels

topic: reportingrelated to terminal output and user-facing messages and errorstype: proposalproposal for a new feature, often to gather opinions or design the API around the new feature

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions