Title: unittest.mock.create_autospec() can crash when accessing properties from objects · Issue #98301 · python/cpython · GitHub
Open Graph Title: unittest.mock.create_autospec() can crash when accessing properties from objects · Issue #98301 · python/cpython
X Title: unittest.mock.create_autospec() can crash when accessing properties from objects · Issue #98301 · python/cpython
Description: Bug report This crashes. It should not. from unittest.mock import create_autospec class X: @property def myprop(self): raise Exception("some bug") create_autospec(X()) Now you could tell for me to fix X. The problem though is that in my ...
Open Graph Description: Bug report This crashes. It should not. from unittest.mock import create_autospec class X: @property def myprop(self): raise Exception("some bug") create_autospec(X()) Now you could tell for me to ...
X Description: Bug report This crashes. It should not. from unittest.mock import create_autospec class X: @property def myprop(self): raise Exception("some bug") create_autospec(X()) Now you could tell ...
Opengraph URL: https://github.com/python/cpython/issues/98301
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"unittest.mock.create_autospec() can crash when accessing properties from objects","articleBody":"\u003c!--\r\n If you're new to Python and you're not sure whether what you're experiencing is a bug, the CPython issue tracker is not\r\n the right place to seek help. Consider the following options instead:\r\n\r\n - reading the Python tutorial: https://docs.python.org/3/tutorial/\r\n - posting in the \"Users\" category on discuss.python.org: https://discuss.python.org/c/users/7\r\n - emailing the Python-list mailing list: https://mail.python.org/mailman/listinfo/python-list\r\n - searching our issue tracker (https://github.com/python/cpython/issues) to see if\r\n your problem has already been reported\r\n--\u003e\r\n\r\n# Bug report\r\n\r\nThis crashes. It should not.\r\n```\r\nfrom unittest.mock import create_autospec\r\n\r\nclass X:\r\n @property\r\n def myprop(self):\r\n raise Exception(\"some bug\")\r\n\r\ncreate_autospec(X())\r\n```\r\n\r\nNow you could tell for me to fix `X`. The problem though is that in my project the problem is much more complex. X is some other class that is being autospeced and the getter touches some mock objects it does not like.\r\n\r\n# Your environment\r\n\r\n- CPython versions tested on: 3.10\r\n- Operating system and architecture: Windows\r\n\r\n# Fix\r\n\r\n```\r\n--- a\\unittest\\mock.py\r\n+++ b\\unittest\\mock.py\r\n for attr in dir(spec):\r\n- if iscoroutinefunction(getattr(spec, attr, None)):\r\n- _spec_asyncs.append(attr)\r\n+ try::\r\n+ value = getattr(spec, attr, None)\r\n+ except:\r\n+ pass\r\n+ else:\r\n+ if iscoroutinefunction(value):\r\n+ _spec_asyncs.append(attr)\r\n```","author":{"url":"https://github.com/joaoe","@type":"Person","name":"joaoe"},"datePublished":"2022-10-15T21:03:57.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/98301/cpython/issues/98301"}
| 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:9468f3b5-5196-cb05-8283-f7fd593f0bf0 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DE5A:1A2C82:ACEB9:DFBEA:696B2E8C |
| html-safe-nonce | 7a018c16821db3fe22f4a992df8a8bed6616d3c5d497d2f8aef77adc0c044923 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERTVBOjFBMkM4MjpBQ0VCOTpERkJFQTo2OTZCMkU4QyIsInZpc2l0b3JfaWQiOiI4NzU5Nzc5MzM3NDgxOTU3MDA1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 944e5ddb8573589c91833a2a77a7b8ec3385e830127f0cfc2a259f6e36d947dd |
| hovercard-subject-tag | issue:1410290104 |
| 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/98301/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9d10491ab8b821766a4819fc5d89ddc7bf1a03f0b7fba47fddf6bee2025b0865/python/cpython/issues/98301 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9d10491ab8b821766a4819fc5d89ddc7bf1a03f0b7fba47fddf6bee2025b0865/python/cpython/issues/98301 |
| og:image:alt | Bug report This crashes. It should not. from unittest.mock import create_autospec class X: @property def myprop(self): raise Exception("some bug") create_autospec(X()) Now you could tell for me to ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | joaoe |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5f99f7c1d70f01da5b93e5ca90303359738944d8ab470e396496262c66e60b8d |
| 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 | 82560a55c6b2054555076f46e683151ee28a19bc |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width