Skip to content

Commit

Permalink
Use and test parent stack level
Browse files Browse the repository at this point in the history
  • Loading branch information
flying-sheep committed Feb 6, 2019
1 parent 3d07763 commit 6f6f1f5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions legacy_api_wrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))}

Expand Down
14 changes: 11 additions & 3 deletions tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import warnings
from inspect import signature

import pytest

from legacy_api_wrap import legacy_api


Expand All @@ -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

Expand Down

0 comments on commit 6f6f1f5

Please sign in to comment.