Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

88 lignes
2.7KB

  1. """Deprecation messages and bits of code used elsewhere in the codebase that
  2. is planned to be removed in the next pytest release.
  3. Keeping it in a central location makes it easy to track what is deprecated and should
  4. be removed when the time comes.
  5. All constants defined in this module should be either instances of
  6. :class:`PytestWarning`, or :class:`UnformattedWarning`
  7. in case of warnings which need to format their messages.
  8. """
  9. from warnings import warn
  10. from _pytest.warning_types import PytestDeprecationWarning
  11. from _pytest.warning_types import UnformattedWarning
  12. # set of plugins which have been integrated into the core; we use this list to ignore
  13. # them during registration to avoid conflicts
  14. DEPRECATED_EXTERNAL_PLUGINS = {
  15. "pytest_catchlog",
  16. "pytest_capturelog",
  17. "pytest_faulthandler",
  18. }
  19. FILLFUNCARGS = UnformattedWarning(
  20. PytestDeprecationWarning,
  21. "{name} is deprecated, use "
  22. "function._request._fillfixtures() instead if you cannot avoid reaching into internals.",
  23. )
  24. PYTEST_COLLECT_MODULE = UnformattedWarning(
  25. PytestDeprecationWarning,
  26. "pytest.collect.{name} was moved to pytest.{name}\n"
  27. "Please update to the new name.",
  28. )
  29. YIELD_FIXTURE = PytestDeprecationWarning(
  30. "@pytest.yield_fixture is deprecated.\n"
  31. "Use @pytest.fixture instead; they are the same."
  32. )
  33. MINUS_K_DASH = PytestDeprecationWarning(
  34. "The `-k '-expr'` syntax to -k is deprecated.\nUse `-k 'not expr'` instead."
  35. )
  36. MINUS_K_COLON = PytestDeprecationWarning(
  37. "The `-k 'expr:'` syntax to -k is deprecated.\n"
  38. "Please open an issue if you use this and want a replacement."
  39. )
  40. WARNING_CAPTURED_HOOK = PytestDeprecationWarning(
  41. "The pytest_warning_captured is deprecated and will be removed in a future release.\n"
  42. "Please use pytest_warning_recorded instead."
  43. )
  44. FSCOLLECTOR_GETHOOKPROXY_ISINITPATH = PytestDeprecationWarning(
  45. "The gethookproxy() and isinitpath() methods of FSCollector and Package are deprecated; "
  46. "use self.session.gethookproxy() and self.session.isinitpath() instead. "
  47. )
  48. STRICT_OPTION = PytestDeprecationWarning(
  49. "The --strict option is deprecated, use --strict-markers instead."
  50. )
  51. PRIVATE = PytestDeprecationWarning("A private pytest class or function was used.")
  52. # You want to make some `__init__` or function "private".
  53. #
  54. # def my_private_function(some, args):
  55. # ...
  56. #
  57. # Do this:
  58. #
  59. # def my_private_function(some, args, *, _ispytest: bool = False):
  60. # check_ispytest(_ispytest)
  61. # ...
  62. #
  63. # Change all internal/allowed calls to
  64. #
  65. # my_private_function(some, args, _ispytest=True)
  66. #
  67. # All other calls will get the default _ispytest=False and trigger
  68. # the warning (possibly error in the future).
  69. def check_ispytest(ispytest: bool) -> None:
  70. if not ispytest:
  71. warn(PRIVATE, stacklevel=3)