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

Comments

Projects
None yet
3 participants
@bagerard

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

@tomviner

This comment has been minimized.

Show comment
Hide comment
@tomviner

tomviner Apr 22, 2016

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.

Contributor

tomviner commented Apr 22, 2016

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

This comment has been minimized.

Show comment
Hide comment
@bagerard

bagerard Apr 23, 2016

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 :)

bagerard commented Apr 23, 2016

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 nicoddemus closed this in #1654 Jun 24, 2016

nicoddemus added a commit that referenced this issue Jun 24, 2016

Merge pull request #1654 from tomviner/issue1503/remove_collapse_false
Fixes #1503 no longer collapse false explanations

This was referenced Aug 19, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment