Title: bpo-37555: Update _CallList.__contains__ to respect ANY by ElizabethU · Pull Request #14700 · python/cpython · GitHub
Open Graph Title: bpo-37555: Update _CallList.__contains__ to respect ANY by ElizabethU · Pull Request #14700 · python/cpython
X Title: bpo-37555: Update _CallList.__contains__ to respect ANY by ElizabethU · Pull Request #14700 · python/cpython
Description: Greetings! Long time fan of the language, first time submitting a pull request to it.
I have a test on another project that goes something like:
@patch('a.place.to.patch')
def test_a_thing_calls_what_it_should(self, my_mock):
# Set up logic here
my_mock.assert_has_calls([
call(
ANY,
Decimal('20')
),
call(
ANY,
Decimal('10')
)
])
Which fails, where my_mock.call_args_list looks like
[(, Decimal('20')), (, Decimal('10'))]
This seems like wrong behavior. ANY should be happy to be compared to anything, even a random object. I've added a test showing the behavior that fails on master.
Doing some digging, I found that in mock.py _CallList is overriding __contains__ and comparing each item in the tuples with what I'd passed in to assert_has_calls on the right, which means that instead of using ANY.__eq__, it's calling the Django model's __eq__ with ANY as an argument. Django first checks if the thing it's comparing to is another Django model, and returns False if not. So,
Open Graph Description: Greetings! Long time fan of the language, first time submitting a pull request to it. I have a test on another project that goes something like: @patch('a.place.to.patch') def test_a_thing_...
X Description: Greetings! Long time fan of the language, first time submitting a pull request to it. I have a test on another project that goes something like: @patch('a.place.to.patch') def test_...
Opengraph URL: https://github.com/python/cpython/pull/14700
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/checks(.:format) |
| route-controller | pull_requests |
| route-action | checks |
| fetch-nonce | v2:59df0138-db85-6da9-09fd-4294f4c65984 |
| current-catalog-service-hash | 87dc3bc62d9b466312751bfd5f889726f4f1337bdff4e8be7da7c93d6c00a25a |
| request-id | 8702:4BD90:10941AB:172DA2A:696A3624 |
| html-safe-nonce | c3bf4f0560f307b7285b96698cf6e1756a47e1b363dad27449c54ad9e07a6a20 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NzAyOjRCRDkwOjEwOTQxQUI6MTcyREEyQTo2OTZBMzYyNCIsInZpc2l0b3JfaWQiOiI1ODczNTAyODY4NjU0OTI5NDQ0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | d61c115b2dcd31a92b295ee8bee2806cf124c42eb49c2277195f69f96fa982cf |
| hovercard-subject-tag | pull_request:296471815 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,checks,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python/cpython/pull/14700/checks |
| twitter:image | https://avatars.githubusercontent.com/u/5474419?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/5474419?s=400&v=4 |
| og:image:alt | Greetings! Long time fan of the language, first time submitting a pull request to it. I have a test on another project that goes something like: @patch('a.place.to.patch') def test_a_thing_... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 321736bfdb3f591415ae895a0459bec204b26a76caf47ba5c980634cfacc4538 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive full-width full-width-p-0 |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7a9163cefd1ea4bd06f8eb7c082f43e4e53f626f |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width