pytest-dev / pytest-dev/pytest
RFC: Starred arg/kwarg unpacking in Assert rewrites
Nobody has claimed this yet.
- 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 listfrom 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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