pytest-dev / pytest-dev/pytest

alias locals in assertreprcompare for errors

Open
#8,344 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

while writing a test for a own library, i took note, that sometimes the repr is a pain, but repalcing a object with the name of a local would deeply ease the debugging

_______ test_order ____________
    def test_order():
        first = Priorized(priority=1, name="win")
        tied = Priorized(priority=1, name="win2")
        different = Priorized(priority=2, name="nay")
    
        assert not first < tied
        assert not tied < first
        assert first > tied
        assert tied > first
        assert not first == tied  # sorting the same but is not the same
    
        assert different > first
        assert first < different
    
>       assert sorted([different, first, tied, ]) == [first, tied]
E       AssertionError: assert [Priorized(priority=1, name='win'),\n Priorized(priority=1, name='win2'),\n Priorized(priority=2, name='nay')] == [Priorized(priority=1, name='win'), Priorized(priority=1, name='win2')]
E         Left contains one more item: Priorized(priority=2, name='nay')
E         Full diff:
E           [
E            Priorized(priority=1, name='win'),
E            Priorized(priority=1, name='win2'),
E         +  Priorized(priority=2, name='nay'),
E           ]

testing/test_simple.py:65: AssertionError

the error could instead be

>       assert sorted([different, first, tied, ]) == [first, tied]
E       AssertionError: assert [first, tied, different] == [first, tied]
E         Left contains one more item: different
E         Full diff:
E           [
E            first,
E            tied,
E         +  different,
E           ]

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.

Research direction

Start at the assertreprcompare entry point and reproduce the example from testing/test_simple.py:65. Trace how assertion values are rendered, then determine how local names could be substituted in the displayed output. Done means the shown assertion reports first, tied, and different instead of their reprs, with existing assertion output preserved elsewhere.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.