Title: TestCase.assertRaisesString · Issue #123013 · python/cpython · GitHub
Open Graph Title: TestCase.assertRaisesString · Issue #123013 · python/cpython
X Title: TestCase.assertRaisesString · Issue #123013 · python/cpython
Description: Feature or enhancement Proposal: More often I need to check for exact error message and do not need regular expression. For pure convenience, this would look like. def assertRaisesString(self, exc, string, *args, **kwargs): escaped = re....
Open Graph Description: Feature or enhancement Proposal: More often I need to check for exact error message and do not need regular expression. For pure convenience, this would look like. def assertRaisesString(self, exc,...
X Description: Feature or enhancement Proposal: More often I need to check for exact error message and do not need regular expression. For pure convenience, this would look like. def assertRaisesString(self, exc,...
Opengraph URL: https://github.com/python/cpython/issues/123013
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"TestCase.assertRaisesString","articleBody":"# Feature or enhancement\n\n### Proposal:\n\nMore often I need to check for exact error message and do not need regular expression.\n\nFor pure convenience, this would look like.\n\n```python\ndef assertRaisesString(self, exc, string, *args, **kwargs):\n escaped = re.escape(string)\n return self.assertRaisesRegex(exc, f'^{escaped}$', *args, **kwds)\n```\n\nHowever, as using regular expression is overkill, could just add pure string case to `_AssertRaisesBaseContext`:\n\n```python\nclass _AssertRaisesBaseContext(_BaseTestCaseContext):\n\n def __init__(self, expected, test_case, expected_string=None, regex=True):\n ...\n\nclass _AssertRaisesContext(_AssertRaisesBaseContext):\n def __exit__(self, exc_type, exc_value, tb):\n expected_string = self.expected_string\n exc_string = str(exc_value)\n if self.regex:\n # perform regex\n else:\n # compare strings\n```\n\n### Has this already been discussed elsewhere?\n\nThis is a minor feature, which does not need previous discussion elsewhere\n\n### Links to previous discussion of this feature:\n\n_No response_\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-123023\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/dg-pb","@type":"Person","name":"dg-pb"},"datePublished":"2024-08-14T15:30:14.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":8},"url":"https://github.com/123013/cpython/issues/123013"}
| 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:c5666050-592b-d232-342c-38753032a5ee |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A864:121520:B6E7A2:F0E4C2:696B848B |
| html-safe-nonce | 1d7564ee1436b474f80779adf676c75269e8a78aee457cdbe4778cc90e376e89 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBODY0OjEyMTUyMDpCNkU3QTI6RjBFNEMyOjY5NkI4NDhCIiwidmlzaXRvcl9pZCI6IjQwNzE3Njg5MjQxMTYxOTAzNDciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 10a75c96d3aa520a677b39c2883a41575af9665d622f6527ddf2f70c69fcc46d |
| hovercard-subject-tag | issue:2466184427 |
| 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/123013/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4d46751903d1db54a90d4789d0e16c253ca7def072e20ee8d67330694bced677/python/cpython/issues/123013 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4d46751903d1db54a90d4789d0e16c253ca7def072e20ee8d67330694bced677/python/cpython/issues/123013 |
| og:image:alt | Feature or enhancement Proposal: More often I need to check for exact error message and do not need regular expression. For pure convenience, this would look like. def assertRaisesString(self, exc,... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dg-pb |
| 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 | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width