pytest-dev / pytest-dev/pytest
Generalize pytest_assertrepr_compare() hook so it works with any assert
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 14.5k
- Forks
- 3.4k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 35
Description
Hi All,
I am new to pytest. I need help with assertion hook.
There is pytest_assertrepr_compare() hook for assertion expression comparison.
However the hook will work only if assert statement has both left and right expressions along with operands.
Example
- assert 1 == 2
- assert i == j
- assert 'a' not in 'assert':
My use case is - Every time an assertion failure happens, I need a hook to enter in and manage few test specific variables defined inside my conftest.
But since the hook requires an operator, it will not work for below assert statements.
- assert i
- assert not j
etc.
Is there a solution to this, that allows me to enter a hook on every assertion failure ?
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 by reading the pytest_assertrepr_compare() hook and the assertion-handling path described in the issue, along with how conftest variables are accessed. Determine whether a general assertion-failure hook can cover bare and negated assertions without changing comparison behavior. Done should include a documented, tested way to handle every assertion failure.
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
- Needs clarification
- Newbie friendliness
- 25/100