skipdoctest.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. """Decorators marks that a doctest should be skipped, for both python 2 and 3.
  2. The IPython.testing.decorators module triggers various extra imports, including
  3. numpy and sympy if they're present. Since this decorator is used in core parts
  4. of IPython, it's in a separate module so that running IPython doesn't trigger
  5. those imports."""
  6. #-----------------------------------------------------------------------------
  7. # Copyright (C) 2009-2011 The IPython Development Team
  8. #
  9. # Distributed under the terms of the BSD License. The full license is in
  10. # the file COPYING, distributed as part of this software.
  11. #-----------------------------------------------------------------------------
  12. #-----------------------------------------------------------------------------
  13. # Imports
  14. #-----------------------------------------------------------------------------
  15. import sys
  16. #-----------------------------------------------------------------------------
  17. # Decorators
  18. #-----------------------------------------------------------------------------
  19. def skip_doctest(f):
  20. """Decorator - mark a function or method for skipping its doctest.
  21. This decorator allows you to mark a function whose docstring you wish to
  22. omit from testing, while preserving the docstring for introspection, help,
  23. etc."""
  24. f.skip_doctest = True
  25. return f
  26. def skip_doctest_py3(f):
  27. """Decorator - skip the doctest under Python 3."""
  28. f.skip_doctest = (sys.version_info[0] >= 3)
  29. return f
  30. def skip_doctest_py2(f):
  31. """Decorator - skip the doctest under Python 3."""
  32. f.skip_doctest = (sys.version_info[0] < 3)
  33. return f