pytest-dev / pytest-dev/pytest

RFC: Starred arg/kwarg unpacking in Assert rewrites

Open
#7,693 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

  • a detailed description of the bug or suggestion
  • output of pip list from the virtual environment you are using
  • pytest and operating system versions
  • minimal example if possible

Right now, unpacked arguments render like so:

>           assert f(*args) == expected
E           assert False == True
E            +  where False = <function ...>(*([4, 2, 3, 0, 3, 1, ...], 0))

This would be more readable if the argument tuple were unpacked like so:

E            +  where False = <function ...>([4, 2, 3, 0, 3, 1, ...], 0)

Something similar could apply to keyword arguments, though that may prove trickier: more edge cases.

Notes from preliminary hacking on visit_Assert, etc:

  • The "trivial" cases of List/Tuple/Dict literal unpacking aren't too bad
  • May require some codegen to handle formatting – ', '.join(args), but handling termwidth
  • Unpacking calls with multiple starred expressions will be confusing – fallback to existing path

No guarantees as to if I'll take this up – certainly not until mid-September at the earliest – but the idea's written up for myself (or someone else) to implement later.

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 with the preliminary work around visit_Assert and the existing assertion-rewrite rendering path. Determine how literal starred positional arguments should be formatted, including term width and multiple starred expressions, and assess the additional keyword-argument edge cases. Done means readable unpacked output with a defined fallback for confusing cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.