pytest-dev / pytest-dev/pytest

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

Open
#5,285 1 comment 7 reactions 1 assignee View on GitHub

@Pierre-Sassoulas is already working on this.

Since Feb 6, 2024.

topic: reporting type: proposal
Dominant language
Python
Stars
14.5k
Forks
3.4k
Avg merge
2d 9h
Merged PRs (30d)
35

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.