Consider adding `doctest.skip_if` decorator
@sobolevn y travaille déjà.
Depuis le 29/3/2024.
- Langage dominant
- Python
- Étoiles
- 77.2k
- Forks
- 36k
- Métriques de merge des PR
- Métriques de PR en attente
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 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:
However, this is just test functions. For library functions it would be much harder to do.
You have to jiggle __doc__ attribute around.
Since https://github.com/python/cpython/pull/117297 we now have correct skipped count for doctest + unittest integration.
So, I propose adding this decorator to doctest.py
def skip_if(condition):
def decorator(func):
if condition and HAVE_DOCSTRINGS:
func.__doc__ = ">>> pass # doctest: +SKIP"
return func
return decorator
It will allow us skipping some tests conditionally with the proper reported results.
Refs https://github.com/python/cpython/pull/116758
CC @serhiy-storchaka and @furkanonder
Linked PRs
- gh-122935
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Évaluation
Cette issue n'a pas encore été évaluée.