Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

warnings: fix missing None in existing hook & add some docs #7288

Merged
merged 4 commits into from Jun 2, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions doc/en/deprecations.rst
Expand Up @@ -20,6 +20,17 @@ Below is a complete list of all pytest features which are considered deprecated.
:ref:`standard warning filters <warnings>`.


The ``pytest_warning_captured`` hook
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't realize we had a deprecation file. Thanks @bluetech

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. deprecated:: 6.0

This hook has an `item` parameter which cannot be serialized by ``pytest-xdist``.

Use the ``pytest_warning_recored`` hook instead, which replaces the ``item`` parameter
by a ``nodeid`` parameter.


The ``pytest._fillfuncargs`` function
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
26 changes: 18 additions & 8 deletions src/_pytest/hookspec.py
Expand Up @@ -623,9 +623,15 @@ def pytest_terminal_summary(terminalreporter, exitstatus, config):


@hookspec(historic=True, warn_on_impl=WARNING_CAPTURED_HOOK)
def pytest_warning_captured(warning_message, when, item, location):
def pytest_warning_captured(
warning_message: "warnings.WarningMessage",
when: str,
item,
location: Optional[Tuple[str, int, str]],
) -> None:
"""(**Deprecated**) Process a warning captured by the internal pytest warnings plugin.

.. deprecated:: 6.0
This hook is considered deprecated and will be removed in a future pytest version.
Use :func:`pytest_warning_recorded` instead.

Expand All @@ -644,8 +650,9 @@ def pytest_warning_captured(warning_message, when, item, location):
The item being executed if ``when`` is ``"runtest"``, otherwise ``None``.

:param tuple location:
Holds information about the execution context of the captured warning (filename, linenumber, function).
``function`` evaluates to <module> when the execution context is at the module level.
When available, holds information about the execution context of the captured
warning (filename, linenumber, function). ``function`` evaluates to <module>
when the execution context is at the module level.
"""


Expand All @@ -654,8 +661,8 @@ def pytest_warning_recorded(
warning_message: "warnings.WarningMessage",
when: str,
nodeid: str,
location: Tuple[str, int, str],
):
location: Optional[Tuple[str, int, str]],
) -> None:
"""
Process a warning captured by the internal pytest warnings plugin.

Expand All @@ -672,9 +679,12 @@ def pytest_warning_recorded(

:param str nodeid: full id of the item

:param tuple location:
Holds information about the execution context of the captured warning (filename, linenumber, function).
``function`` evaluates to <module> when the execution context is at the module level.
:param tuple|None location:
When available, holds information about the execution context of the captured
warning (filename, linenumber, function). ``function`` evaluates to <module>
when the execution context is at the module level.

.. versionadded:: 6.0
"""


Expand Down
7 changes: 6 additions & 1 deletion src/_pytest/warnings.py
Expand Up @@ -112,7 +112,12 @@ def catch_warnings_for_item(config, ihook, when, item):

for warning_message in log:
ihook.pytest_warning_captured.call_historic(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we usually update deprecated hooks? Asking for my own knowledge. I wasn't sure when I made the change for pytest_warning_recorded

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense to update deprecated hooks if it's a simple bugfix like this.

kwargs=dict(warning_message=warning_message, when=when, item=item)
kwargs=dict(
warning_message=warning_message,
when=when,
item=item,
location=None,
)
)
ihook.pytest_warning_recorded.call_historic(
kwargs=dict(
Expand Down