Skip to content

Documentation: misleading deep inspection #411

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

Closed
pytestbot opened this issue Dec 21, 2013 · 1 comment
Closed

Documentation: misleading deep inspection #411

pytestbot opened this issue Dec 21, 2013 · 1 comment
Labels
good first issue easy issue that is friendly to new contributor type: docs documentation improvement, missing or needing clarification type: enhancement new feature or API change, should be merged into features branch

Comments

@pytestbot
Copy link
Contributor

Originally reported by: BitBucket: PeterSlickers, GitHub: PeterSlickers


I recently started using pytest und thus read some the documentation.

On page "http://pytest.org/latest/assert.html" in section "Defining your own assertion comparison" I found an example 'test_foocompare.py'.

class Foo:
    def __init__(self, val):
         self.val = val

 f1 = Foo(1)
 f2 = Foo(2)
 assert f1 == f2

Class 'foo' is very simple and it does not define any of Pythons magic methods for comparison like ne, cmp etc. Thus, a comparison of two instances of Foo will be accomplished by comparing the unique ID of the two objects:

id(f1) == id(f2)

Even if both instances are initiated with the same value, the comparison for equality will fail:

id(Foo(1)) == id(Foo(1))  --> False

Applying the deep inspection produces the following misleading result:

'=================================================== FAILURES ===================================================
_________________________________________________ test_compare _________________________________________________

    def test_compare():
        f1 = Foo(1)
        f2 = Foo(1)
>       assert f1 == f2
E    assert Comparing Foo instances:
E         vals: 1 != 1

test_foocompare.py:9: AssertionError
1 failed in 0.01 seconds

With best regards

Peter


@pytestbot
Copy link
Contributor Author

Original comment by holger krekel (BitBucket: hpk42, GitHub: hpk42):


I agree that it's a bit confusing. Do you have an idea on how to improve it while keeping it simple enough? If so, are you maybe ready for a pull request?

thanks, holger

@pytestbot pytestbot added the type: enhancement new feature or API change, should be merged into features branch label Jun 15, 2015
@pfctdayelise pfctdayelise added type: docs documentation improvement, missing or needing clarification good first issue easy issue that is friendly to new contributor labels Jul 25, 2015
Bjwebb added a commit to Bjwebb/pytest that referenced this issue Sep 21, 2015
This makes the example make more sense, because now Foo(1) == Foo(1) is
true. Fixes pytest-dev#411
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue easy issue that is friendly to new contributor type: docs documentation improvement, missing or needing clarification type: enhancement new feature or API change, should be merged into features branch
Projects
None yet
Development

No branches or pull requests

2 participants