Title: unittest.mock.seal doesn't work as expected with AsyncMock · Issue #100287 · python/cpython · GitHub
Open Graph Title: unittest.mock.seal doesn't work as expected with AsyncMock · Issue #100287 · python/cpython
X Title: unittest.mock.seal doesn't work as expected with AsyncMock · Issue #100287 · python/cpython
Description: I noticed this while reviewing #100252 (comment) I believe the following test case should pass, but it doesn't on main import unittest from unittest.mock import Mock, seal class AsyncClass: async def async_method(self): pass def normal_m...
Open Graph Description: I noticed this while reviewing #100252 (comment) I believe the following test case should pass, but it doesn't on main import unittest from unittest.mock import Mock, seal class AsyncClass: async d...
X Description: I noticed this while reviewing #100252 (comment) I believe the following test case should pass, but it doesn't on main import unittest from unittest.mock import Mock, seal class AsyncClass: asy...
Opengraph URL: https://github.com/python/cpython/issues/100287
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"unittest.mock.seal doesn't work as expected with AsyncMock","articleBody":"I noticed this while reviewing https://github.com/python/cpython/pull/100252#discussion_r1050456588\r\n\r\nI believe the following test case should pass, but it doesn't on main\r\n\r\n```python\r\nimport unittest\r\nfrom unittest.mock import Mock, seal\r\n\r\nclass AsyncClass:\r\n async def async_method(self): pass\r\n def normal_method(self): pass\r\n\r\nclass Case(unittest.TestCase):\r\n def test_spec_normal_methods_on_class_with_mock_seal(self):\r\n mock = Mock(AsyncClass)\r\n seal(mock)\r\n # test passes, aka this raises AttributError\r\n with self.assertRaises(AttributeError):\r\n mock.normal_method\r\n # test fails, aka this does not raise AttributError\r\n with self.assertRaises(AttributeError):\r\n mock.async_method\r\n\r\nunittest.main()\r\n```\r\n\r\nIt's easy to fix, just need to move the clause that handles AsyncMock after the `if self._mock_sealed:` check.\r\n\r\ncc @sobolevn who moved the `if self._mock_sealed:` check earlier in https://github.com/python/cpython/pull/28300/files , but not all the way\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-100496\n* gh-100506\n* gh-100508\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/hauntsaninja","@type":"Person","name":"hauntsaninja"},"datePublished":"2022-12-16T08:15:09.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/100287/cpython/issues/100287"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:28e5d831-b196-23ca-599b-12b098da5207 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DF5C:35D476:1B7D6E6:26D4DA4:696901C9 |
| html-safe-nonce | a223c2599d49b65255a704aa690f0422f4d0329df8632e17076bd449ab623c64 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERjVDOjM1RDQ3NjoxQjdENkU2OjI2RDREQTQ6Njk2OTAxQzkiLCJ2aXNpdG9yX2lkIjoiNDE4NTgwOTM0MjQzNjAxNjU4NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | f2c76dcfd97356b59086a0a76d3702b26dee832599e8b5f808b1d9942b978762 |
| hovercard-subject-tag | issue:1499783366 |
| github-keyboard-shortcuts | repository,issues,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/_view_fragments/issues/show/python/cpython/100287/issue_layout |
| twitter:image | https://opengraph.githubassets.com/fb67d7e86c780af35144e236814967cc87ce9a113a2659c5afe13a91244ff903/python/cpython/issues/100287 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/fb67d7e86c780af35144e236814967cc87ce9a113a2659c5afe13a91244ff903/python/cpython/issues/100287 |
| og:image:alt | I noticed this while reviewing #100252 (comment) I believe the following test case should pass, but it doesn't on main import unittest from unittest.mock import Mock, seal class AsyncClass: async d... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | hauntsaninja |
| hostname | github.com |
| expected-hostname | github.com |
| None | e6156bd4ef9f2dc8dadf4c49a8f7ed8532186388cef72eda3ccb9f0ab3b8cfca |
| 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 |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | fd1938215b152e2c6a29cf56fec07fd9f91f1203 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width