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 based on the platform
- We have doctests that should be skipped based on a resource availability
- Libraries might want to skip some doctests based on the Python version / any other lib version
Right now we have this hack:
| ifint.__doc__: # simple check for --without-doc-strings, skip if lacking |
| defnon_Python_modules(): r""" |
| |
| Finding Doctests in Modules Not Written in Python |
| ifnothasattr(sys, 'gettrace') ornotsys.gettrace(): |
| deftest_pdb_set_trace(): |
| """Using pdb.set_trace from a doctest. |
| |
| You can use pdb.set_trace from a doctest. To do so, you must |
| ifsupports_unicode: |
| deftest_unicode(): """ |
| Check doctest with a non-ascii filename: |
| |
| >>> doc = ''' |
| ... >>> raise Exception('clé') |
However, this is just test functions. For library functions it would be much harder to do.
You have to jiggle __doc__ attribute around.
Since #117297 we now have correct skipped count for doctest + unittest integration.
So, I propose adding this decorator to doctest.py
defskip_if(condition):
defdecorator(func):
ifconditionandHAVE_DOCSTRINGS:
func.__doc__=">>> pass # doctest: +SKIP"returnfuncreturndecorator
It will allow us skipping some tests conditionally with the proper reported results.
Refs #116758
CC @serhiy-storchaka and @furkanonder
Linked PRs
Feature or enhancement
Right now there's no way to skip the whole test / class doctest. You can only skip individual statements with
# doctest: +SKIPThis causes problems in several use-cases:
Right now we have this hack:
cpython/Lib/test/test_doctest/test_doctest.py
Lines 727 to 730 in 2e9be80
cpython/Lib/test/test_doctest/test_doctest.py
Lines 1999 to 2003 in 2e9be80
cpython/Lib/test/test_doctest/test_doctest.py
Lines 2938 to 2943 in 2e9be80
However, this is just test functions. For library functions it would be much harder to do.
You have to jiggle
__doc__attribute around.Since #117297 we now have correct skipped count for
doctest+unittestintegration.So, I propose adding this decorator to
doctest.pyIt will allow us skipping some tests conditionally with the proper reported results.
Refs #116758
CC @serhiy-storchaka and @furkanonder
Linked PRs
doctest.SkipTestto skip all or some doctest examples #122935