GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Customisable truncation limits · Issue #12765 · pytest-dev/pytest

Customisable truncation limits #12765

New issue
Copy link
New issue
Copy link
Closed
#12766
Closed
Customisable truncation limits#12765
#12766
Copy link

Description

@zhukoff-pavel
zhukoff-pavel
opened on Sep 2, 2024
Issue body actions

Hi!
I've recently encountered a problem regarding basic truncation limits.

What's the problem this feature will solve?

Truncation method allows to set custom max_lines, max_chars, but this mechanism is not used in its only call here, even when max_length (I guess it is used as a synonym to max_chars) can be specified in truncate_if_required.
However, truncate_if_required is not called with any length parameter (see this invocation).

In its basic form, it produces quite small diff, that may not be as intelligible as it is expected to be :(

Example

test.py file:

string_a = """
Code sample:
def a():
    print(10000) #comment
    do_something()

def b():
    print(100000) #comment
    do_something()
"""

string_b = """
Code sample:
def a():
    print(10000) # comment
    do_something()

def b():
    print(100000) # comment
    do_something()
"""

def test():
    assert string_a == string_b

This results in

% pytest test.py
============================================================================================== test session starts ==============================================================================================
platform darwin -- Python 3.12.3, pytest-8.3.2, pluggy-1.5.0
rootdir: <root-dir>
collected 1 item                                                                                                                                                                                                

test.py F                                                                                                                                                                                                 [100%]

=================================================================================================== FAILURES ====================================================================================================
_____________________________________________________________________________________________________ test ______________________________________________________________________________________________________

    def test():
>       assert string_a == string_b
E       AssertionError: assert '\nCode sampl...something()\n' == '\nCode sampl...something()\n'
E         
E           
E           Code sample:
E           def a():
E         -     print(10000) # comment
E         ?                   -
E         +     print(10000) #comment...
E         
E         ...Full output truncated (7 lines hidden), use '-vv' to show

test.py:26: AssertionError
============================================================================================ short test summary info ============================================================================================
FAILED test.py::test - AssertionError: assert '\nCode sampl...something()\n' == '\nCode sampl...something()\n'
=============================================================================================== 1 failed in 0.01s ===============================================================================================
                                                                                                      

As seen here, second diff is hidden, when it appears in full diff (with -vv flag specified) (see below):

    def test():
>       assert string_a == string_b
E       AssertionError: assert '\nCode sample:\ndef a():\n    print(10000) #comment\n    do_something()\n\ndef b():\n    print(100000) #comment\n    do_something()\n' == '\nCode sample:\ndef a():\n    print(10000) # comment\n    do_something()\n\ndef b():\n    print(100000) # comment\n    do_something()\n'
E         
E           
E           Code sample:
E           def a():
E         -     print(10000) # comment
E         ?                   -
E         +     print(10000) #comment
E               do_something()
E           
E           def b():
E         -     print(100000) # comment
E         ?                    -
E         +     print(100000) #comment
E               do_something()

test.py:24: AssertionError

Describe the solution you'd like

Some solutions are as follows:

  1. Increase the threshold of truncation (e.g. to 16 lines and respectively, to 16 * 80 chars), but this is still not customisable.
  2. Make those limits customizable (for example, with CLI flags (--truncation-limit-lines and --truncation-limit-chars or something like that).

Additional solutions

This may be surpassed by adding -vv flag, however, there are some problems with this mode, for example, #8998.

Reacted by Aleksandr and Miguel Angel Latorre

Activity

  1. nicoddemus
    closed this as completedin #12766on Sep 21, 2024
  2. nicoddemus
    closed this as completedin d924a63on Sep 21, 2024
  3. pull
    added a commit that references this issue on Sep 21, 2024

    Implement truncation thresholds config options (pytest-dev#12766)

    This issue will close once commit d924a63 is merged into the 'main' branch.
    d924a63
  4. luketainton
    added a commit that references this issue on Jan 5, 2026

    chore(deps): update dependency pytest to v9 (#305)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.