deprecated.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. # -*- coding: utf-8 -*-
  2. """
  3. This module contains deprecation messages and bits of code used elsewhere in the codebase
  4. that is planned to be removed in the next pytest release.
  5. Keeping it in a central location makes it easy to track what is deprecated and should
  6. be removed when the time comes.
  7. All constants defined in this module should be either PytestWarning instances or UnformattedWarning
  8. in case of warnings which need to format their messages.
  9. """
  10. from __future__ import absolute_import
  11. from __future__ import division
  12. from __future__ import print_function
  13. from _pytest.warning_types import PytestDeprecationWarning
  14. from _pytest.warning_types import RemovedInPytest4Warning
  15. from _pytest.warning_types import UnformattedWarning
  16. YIELD_TESTS = "yield tests were removed in pytest 4.0 - {name} will be ignored"
  17. FIXTURE_FUNCTION_CALL = (
  18. 'Fixture "{name}" called directly. Fixtures are not meant to be called directly,\n'
  19. "but are created automatically when test functions request them as parameters.\n"
  20. "See https://docs.pytest.org/en/latest/fixture.html for more information about fixtures, and\n"
  21. "https://docs.pytest.org/en/latest/deprecations.html#calling-fixtures-directly about how to update your code."
  22. )
  23. FIXTURE_NAMED_REQUEST = PytestDeprecationWarning(
  24. "'request' is a reserved name for fixtures and will raise an error in future versions"
  25. )
  26. CFG_PYTEST_SECTION = "[pytest] section in {filename} files is no longer supported, change to [tool:pytest] instead."
  27. GETFUNCARGVALUE = RemovedInPytest4Warning(
  28. "getfuncargvalue is deprecated, use getfixturevalue"
  29. )
  30. RAISES_MESSAGE_PARAMETER = PytestDeprecationWarning(
  31. "The 'message' parameter is deprecated.\n"
  32. "(did you mean to use `match='some regex'` to check the exception message?)\n"
  33. "Please see:\n"
  34. " https://docs.pytest.org/en/4.6-maintenance/deprecations.html#message-parameter-of-pytest-raises"
  35. )
  36. RESULT_LOG = PytestDeprecationWarning(
  37. "--result-log is deprecated and scheduled for removal in pytest 5.0.\n"
  38. "See https://docs.pytest.org/en/latest/deprecations.html#result-log-result-log for more information."
  39. )
  40. RAISES_EXEC = PytestDeprecationWarning(
  41. "raises(..., 'code(as_a_string)') is deprecated, use the context manager form or use `exec()` directly\n\n"
  42. "See https://docs.pytest.org/en/latest/deprecations.html#raises-warns-exec"
  43. )
  44. WARNS_EXEC = PytestDeprecationWarning(
  45. "warns(..., 'code(as_a_string)') is deprecated, use the context manager form or use `exec()` directly.\n\n"
  46. "See https://docs.pytest.org/en/latest/deprecations.html#raises-warns-exec"
  47. )
  48. PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST = (
  49. "Defining 'pytest_plugins' in a non-top-level conftest is no longer supported "
  50. "because it affects the entire directory tree in a non-explicit way.\n"
  51. " {}\n"
  52. "Please move it to a top level conftest file at the rootdir:\n"
  53. " {}\n"
  54. "For more information, visit:\n"
  55. " https://docs.pytest.org/en/latest/deprecations.html#pytest-plugins-in-non-top-level-conftest-files"
  56. )
  57. PYTEST_CONFIG_GLOBAL = PytestDeprecationWarning(
  58. "the `pytest.config` global is deprecated. Please use `request.config` "
  59. "or `pytest_configure` (if you're a pytest plugin) instead."
  60. )
  61. PYTEST_ENSURETEMP = RemovedInPytest4Warning(
  62. "pytest/tmpdir_factory.ensuretemp is deprecated, \n"
  63. "please use the tmp_path fixture or tmp_path_factory.mktemp"
  64. )
  65. PYTEST_LOGWARNING = PytestDeprecationWarning(
  66. "pytest_logwarning is deprecated, no longer being called, and will be removed soon\n"
  67. "please use pytest_warning_captured instead"
  68. )
  69. PYTEST_WARNS_UNKNOWN_KWARGS = UnformattedWarning(
  70. PytestDeprecationWarning,
  71. "pytest.warns() got unexpected keyword arguments: {args!r}.\n"
  72. "This will be an error in future versions.",
  73. )
  74. PYTEST_PARAM_UNKNOWN_KWARGS = UnformattedWarning(
  75. PytestDeprecationWarning,
  76. "pytest.param() got unexpected keyword arguments: {args!r}.\n"
  77. "This will be an error in future versions.",
  78. )