Hi Floris and thanks for the feedback.

Unfortunately, this does not solve my usecase. I'm trying to handle cases
where the following statement would pass:

    assert myfunc(failing_input) == False

But where this next statement would fail using my custom report:

    assert myfunc(failing_input)

Calling myfunc() needs to return True or False (or at least Truthy or
Falsy)--this is locked-in behavior.

The assert_myfunc() in my original post is a wrapper that does basically
the same thing as your example. Although I omitted the native assert in my
examples because it is only evaluated when it's already guaranteed to pass.


On Sat, Mar 17, 2018 at 5:04 PM, Floris Bruynooghe <f...@devork.be> wrote:

> Hi Shawn,
>
> Shawn Brown <03sjbr...@gmail.com> writes:
>
> >  I understand how to use pytest_assertrepr_compare() to return custom
> > assertion reports--but this interface requires a comparison operator. I'm
> > hoping to write a plugin that makes custom reports for statements like:
> >
> >     assert myfunc(myobj)
> >
> > Where myfunc() returns True or False. But without an operator (e.g.
> "=="),
> > I can't intercept the results to build my custom report.
>
> After refreshing my mind on the AST-rewriting code again -that's always
> tricky- I think you have been looking into the wrong direction.  I
> believe something as simple as this might do:
>
> def test_foo():
>     assert myfunc(42)
>
> def myfunc(*args):
>     __tracebackhide__
>     if not args:
>        pytest.fail('Hello there\nLook, a multi-line message')
>        raise AssertionError('multi\nline')  # alternative, never gets here
>     return True
>
> Does this solve your usecase?
>
> Cheers,
> Floris
>
_______________________________________________
pytest-dev mailing list
pytest-dev@python.org
https://mail.python.org/mailman/listinfo/pytest-dev

Reply via email to