pytest-dev / pytest-dev/pytest

`pytest_assertrepr_compare` hook should take the same arguments as `pytest_assertion_pass`

Open
#11,984 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

What's the problem this feature will solve?

in my plugin (pytest-robotframework), i want to be able to log both passing and failing assertions in the same way, as a keyword in the robot log with the original expression from the assert statement. for example, the following test would produce this output in the robot log:

def test_foo():
    left = 1
    right = 1
    assert left == right

265295074-c2525ccf-c1c6-4c06-be79-c36fefd3bed4

however i can't do that with failing assertions, because pytest_assertrepr_compare does not have an orig argument, so only the actual values can be displayed, not the original left == right expression from the assert statement:

image

Describe the solution you'd like

either:

  1. add the orig argument from pytest_assertion_pass to pytest_assertrepr_compare. the other arguments would be useful too: item, lineno, expl (expl would be the default explanation or the explanation returned from a previous hook)
  2. create a new pytest_assertion_fail hook that takes the same arguments as pytest_assertion_pass

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 by locating the pytest_assertrepr_compare and pytest_assertion_pass hook implementations and their existing call sites or tests. Compare the proposed APIs, then determine which design can expose the original assertion expression for failing assertions; done means an agreed hook behavior is implemented and covered by the relevant hook tests.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.