Assertion rewrite breaks for objects that reimplement __getattr__#4632
Conversation
60d0636 to
266c0ae
Compare
__getattr__
nicoddemus
left a comment
There was a problem hiding this comment.
Thanks a lot for the PR, LGTM!
Can you please update the changelog entry then rebase and target master instead? This is a bugfix so it should go in the next patch version 4.1.1. 👍
Codecov Report
@@ Coverage Diff @@
## features #4632 +/- ##
============================================
- Coverage 95.76% 95.74% -0.02%
============================================
Files 111 111
Lines 24683 24702 +19
Branches 2446 2447 +1
============================================
+ Hits 23637 23652 +15
- Misses 739 743 +4
Partials 307 307
Continue to review full report at Codecov.
|
1 similar comment
Codecov Report
@@ Coverage Diff @@
## features #4632 +/- ##
============================================
- Coverage 95.76% 95.74% -0.02%
============================================
Files 111 111
Lines 24683 24702 +19
Branches 2446 2447 +1
============================================
+ Hits 23637 23652 +15
- Misses 739 743 +4
Partials 307 307
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## features #4632 +/- ##
===========================================
- Coverage 95.76% 95.56% -0.2%
===========================================
Files 111 111
Lines 24683 24702 +19
Branches 2446 2447 +1
===========================================
- Hits 23637 23607 -30
- Misses 739 774 +35
- Partials 307 321 +14
Continue to review full report at Codecov.
|
Pytest rewrites assertions so that the items on each side of a comoparison will have easier-to-read names in case of an assertion error. Before doing this, it checks to make sure the object doesn't have a __name__ attribute; however, it uses `hasattr` so if the objects __getattr__ is broken then the test failure message will be the stack trace for this failure instead of a rewritten assertion.
When rewriting assertions, pytest makes a call to `__name__` on each object in a comparision. If one of the objects has reimplemented `__getattr__`, they could fail trying to fetch `__name__` with an error other than `AttributeError`, which is what `hasattr` catches. In this case, the stack trace for the failed `__getattr__` call will show up in the pytest output, even though it isn't related to the test failing. This change fixes that by catching exceptions that `hasattr` throws.
7535b4c to
6c89c89
Compare
6c89c89 to
77da4f1
Compare
|
@nicoddemus I think this is ready to go now. |
|
Yes, thanks again! |
This fix addresses #4631.