From 8864cb7367af3add2c412cbc3d57f1599ef20c00 Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Sun, 9 Jan 2022 08:35:36 +0200 Subject: [PATCH] Avoid non-stantdard approached for warning emitting --- pytest_asyncio/plugin.py | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/pytest_asyncio/plugin.py b/pytest_asyncio/plugin.py index 44165602..813a638e 100644 --- a/pytest_asyncio/plugin.py +++ b/pytest_asyncio/plugin.py @@ -5,7 +5,6 @@ import functools import inspect import socket -import sys import warnings import pytest @@ -17,7 +16,7 @@ class Mode(str, enum.Enum): LEGACY = "legacy" -LEGACY_MODE = pytest.PytestDeprecationWarning( +LEGACY_MODE = DeprecationWarning( "The 'asyncio_mode' default value will change to 'strict' in future, " "please explicitly use 'asyncio_mode=strict' or 'asyncio_mode=auto' " "in pytest configuration file." @@ -110,21 +109,7 @@ def pytest_configure(config): "run using an asyncio event loop", ) if _get_asyncio_mode(config) == Mode.LEGACY: - _issue_warning_captured(LEGACY_MODE, config.hook, stacklevel=1) - - -def _issue_warning_captured(warning, hook, *, stacklevel=1): - # copy-paste of pytest internal _pytest.warnings._issue_warning_captured function - with warnings.catch_warnings(record=True) as records: - warnings.simplefilter("always", type(warning)) - warnings.warn(LEGACY_MODE, stacklevel=stacklevel) - frame = sys._getframe(stacklevel - 1) - location = frame.f_code.co_filename, frame.f_lineno, frame.f_code.co_name - hook.pytest_warning_recorded.call_historic( - kwargs=dict( - warning_message=records[0], when="config", nodeid="", location=location - ) - ) + config.issue_config_time_warning(LEGACY_MODE, stacklevel=2) @pytest.mark.tryfirst @@ -222,7 +207,7 @@ def pytest_fixture_setup(fixturedef, request): ) warnings.warn( LEGACY_ASYNCIO_FIXTURE.format(name=name), - pytest.PytestDeprecationWarning, + DeprecationWarning, ) else: # asyncio_mode is STRICT,