Title: Consider adding `doctest.skip_if` decorator · Issue #117364 · python/cpython · GitHub
Open Graph Title: Consider adding `doctest.skip_if` decorator · Issue #117364 · python/cpython
X Title: Consider adding `doctest.skip_if` decorator · Issue #117364 · python/cpython
Description: Feature or enhancement Right now there's no way to skip the whole test / class doctest. You can only skip individual statements with # doctest: +SKIP This causes problems in several use-cases: You have a doctest that should be skipped ba...
Open Graph Description: Feature or enhancement Right now there's no way to skip the whole test / class doctest. You can only skip individual statements with # doctest: +SKIP This causes problems in several use-cases: You ...
X Description: Feature or enhancement Right now there's no way to skip the whole test / class doctest. You can only skip individual statements with # doctest: +SKIP This causes problems in several use-cases: ...
Opengraph URL: https://github.com/python/cpython/issues/117364
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Consider adding `doctest.skip_if` decorator","articleBody":"# Feature or enhancement\n\nRight now there's no way to skip the whole test / class doctest. You can only skip individual statements with `# doctest: +SKIP`\n\nThis causes problems in several use-cases:\n- You have a doctest that should be skipped based on the platform\n- We have doctests that should be skipped based on a resource availability\n- Libraries might want to skip some doctests based on the Python version / any other lib version\n\nRight now we have this hack: \n\nhttps://github.com/python/cpython/blob/2e9be80c99f635c2f7761e8356b0260922d6e7a6/Lib/test/test_doctest/test_doctest.py#L727-L730\n\nhttps://github.com/python/cpython/blob/2e9be80c99f635c2f7761e8356b0260922d6e7a6/Lib/test/test_doctest/test_doctest.py#L1999-L2003\n\nhttps://github.com/python/cpython/blob/2e9be80c99f635c2f7761e8356b0260922d6e7a6/Lib/test/test_doctest/test_doctest.py#L2938-L2943\n\nHowever, this is just test functions. For library functions it would be much harder to do.\nYou have to jiggle `__doc__` attribute around.\n\nSince https://github.com/python/cpython/pull/117297 we now have correct skipped count for `doctest` + `unittest` integration.\n\nSo, I propose adding this decorator to `doctest.py`\n\n```python\ndef skip_if(condition):\n def decorator(func):\n if condition and HAVE_DOCSTRINGS:\n func.__doc__ = \"\u003e\u003e\u003e pass # doctest: +SKIP\"\n return func\n return decorator\n```\n\nIt will allow us skipping some tests conditionally with the proper reported results.\n\nRefs https://github.com/python/cpython/pull/116758\nCC @serhiy-storchaka and @furkanonder \n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-122935\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/sobolevn","@type":"Person","name":"sobolevn"},"datePublished":"2024-03-29T09:59:25.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/117364/cpython/issues/117364"}
| 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:bd6be17c-3697-2239-4a9a-cc656353753e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BC22:CED76:B16350:F5C3D1:696A86E5 |
| html-safe-nonce | b043acddfbd43af5e407585d6257fcb44efd5d2e7ee648f9ebd43bb084f0f57f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQzIyOkNFRDc2OkIxNjM1MDpGNUMzRDE6Njk2QTg2RTUiLCJ2aXNpdG9yX2lkIjoiMjEyMzYxOTQ4MDAzMjE1MTI2OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 54b1cf6099315f9f14679a3cadbd95a76a3bab1cb08c87a48d011dee900dd101 |
| hovercard-subject-tag | issue:2215043151 |
| 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/117364/issue_layout |
| twitter:image | https://opengraph.githubassets.com/224abb3c4d6a267d74ed19eab84ccd049db12d9ec274659bb4ca3d8a4e72a44c/python/cpython/issues/117364 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/224abb3c4d6a267d74ed19eab84ccd049db12d9ec274659bb4ca3d8a4e72a44c/python/cpython/issues/117364 |
| og:image:alt | Feature or enhancement Right now there's no way to skip the whole test / class doctest. You can only skip individual statements with # doctest: +SKIP This causes problems in several use-cases: You ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | sobolevn |
| hostname | github.com |
| expected-hostname | github.com |
| None | d2aa6dedd7d97fa651b17c40401f2605f309df5ca5fb659bf0554cf34f1de825 |
| 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 | c1dbca8981c5e3d6a69bce2f1d289e732b86241d |
| ui-target | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width