From 6f6f1f5a7e1298c2f953947ac33e423cd7eb59b9 Mon Sep 17 00:00:00 2001 From: Philipp A Date: Wed, 6 Feb 2019 16:33:22 +0100 Subject: [PATCH] Use and test parent stack level --- legacy_api_wrap.py | 1 + tests.py | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/legacy_api_wrap.py b/legacy_api_wrap.py index 0ae4dbf..3e71619 100644 --- a/legacy_api_wrap.py +++ b/legacy_api_wrap.py @@ -73,6 +73,7 @@ def fn_compatible(*args, **kw): f"The specified parameters {old_positionals[:len(args_rest)]!r} are no longer positional. " f"Please specify them like `{old_positionals[0]}={args_rest[0]!r}`", DeprecationWarning, + stacklevel=2, ) kw = {**kw, **dict(zip(old_positionals, args_rest))} diff --git a/tests.py b/tests.py index 2395e07..b50517b 100644 --- a/tests.py +++ b/tests.py @@ -1,5 +1,8 @@ +import warnings from inspect import signature +import pytest + from legacy_api_wrap import legacy_api @@ -19,13 +22,18 @@ def test_new_param_available(): def test_old_positional_order(): - from pytest import warns - - with warns(DeprecationWarning): + with pytest.deprecated_call(): res = new(12, 13, 14) assert res["d"] == 14 +def test_warning_stack(): + with pytest.deprecated_call() as record: + new(12, 13, 14) + w = record.pop() # type: warnings.WarningMessage + assert w.filename == __file__ + + def test_too_many_args(): from pytest import raises