Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

missing evaluated value in report when asserting a boolean attribute (using --assert=rewrite) #1503

Closed
bagerard opened this issue Apr 4, 2016 · 2 comments · Fixed by #1654
Labels
status: help wanted developers would like help from experts on this topic topic: reporting related to terminal output and user-facing messages and errors type: bug problem that needs to be addressed

Comments

@bagerard
Copy link

bagerard commented Apr 4, 2016

Hi there,

First of all, thank you for the amazing work you've done on pytest! It is really cool!
When asserting a boolean attribute of an object, the actual value isn't printed in the output as it would be with other types (int, str, etc). I'm using latest pytest 2.9.1

def test_a():
    class AA():
        pass
    a = AA()
    a.t = False
    assert a.t is True

Provides the following output (using with ---assert=rewrite):

...

  assert a.t is True

E assert <test.AA instance at 0x7fb9399169e0>.t is True

And if run with ---assert=reinterp:

...

  assert a.t is True

E assert False is True
E + where False = <test.AA instance at 0x7f24de4740e0>.t

Thanks

@RonnyPfannschmidt RonnyPfannschmidt added type: bug problem that needs to be addressed status: help wanted developers would like help from experts on this topic topic: reporting related to terminal output and user-facing messages and errors labels Apr 4, 2016
@tomviner
Copy link
Contributor

This is caused by the _collapse_false function, which aims to trim away trivial explanations.

For example this test:

def test_false_value():
    x = 0
    assert bool(x)

Full explanation, with _collapse_false patched out:

    def test_false_value():
        x = 0
>       assert bool(x)
E       assert False
E        +  where False = bool(0)

Trimmed explanation, with _collapse_false back in place:

    def test_false_value():
        x = 0
>       assert bool(x)
E       assert bool(0)

I'm having trouble recreating an example where useful information is trimmed away.

@bagerard
Copy link
Author

Hi tomviner, Thanks for your reply. I wasn't aware of such behaviour and in my case I wasn't sure if my asserted value was a boolean or not. In fact if you take the following test:

def test_foo2():
    mo = Foo(a=False)
#>       assert mo.a
#E       assert <test.Foo instance at 0x7f28a5ff0dd0>.a

The output isn't telling me if mo.a is False or if it's anything else that evalues to False (0 for instance). It turns out that the output is different if it is 0 but without knowing this, you can't tell...
I understand that you want to trim away trivial explanations but personally I find it confusing for newcomers.
This ticket can be switched to "proposal", I suggest to trim away the _collapse_false method :)

tomviner added a commit to tomviner/pytest that referenced this issue Jun 24, 2016
tomviner added a commit to tomviner/pytest that referenced this issue Jun 24, 2016
tomviner added a commit to tomviner/pytest that referenced this issue Jun 24, 2016
tomviner added a commit to tomviner/pytest that referenced this issue Jun 24, 2016
nicoddemus added a commit that referenced this issue Jun 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: help wanted developers would like help from experts on this topic topic: reporting related to terminal output and user-facing messages and errors type: bug problem that needs to be addressed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants