Skip to content

Commit ca423b2

Browse files
committed
Make deprecation calls not depend on a specific pytest path to pass
1 parent f59d44b commit ca423b2

File tree

4 files changed

+13
-20
lines changed

4 files changed

+13
-20
lines changed

python/ipywidgets/ipywidgets/widgets/tests/test_utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,27 @@
77
from ..utils import deprecation
88
from .utils import call_method
99

10-
PYTEST_PATH = inspect.getfile(pytest.Function)
1110
CALL_PATH = inspect.getfile(call_method)
1211

1312
def test_deprecation():
13+
caller_path = inspect.stack(context=0)[1].filename
1414
with pytest.deprecated_call() as record:
1515
deprecation('Deprecated call')
1616
# Make sure the deprecation pointed to the external function calling this test function
1717
assert len(record) == 1
18-
assert record[0].filename == PYTEST_PATH
18+
assert record[0].filename == caller_path
1919

2020
with pytest.deprecated_call() as record:
2121
deprecation('Deprecated call', ['ipywidgets/widgets/tests'])
2222
# Make sure the deprecation pointed to the external function calling this test function
2323
assert len(record) == 1
24-
assert record[0].filename == PYTEST_PATH
24+
assert record[0].filename == caller_path
2525

2626
with pytest.deprecated_call() as record:
2727
deprecation('Deprecated call', 'ipywidgets/widgets/tests')
2828
# Make sure the deprecation pointed to the external function calling this test function
2929
assert len(record) == 1
30-
assert record[0].filename == PYTEST_PATH
30+
assert record[0].filename == caller_path
3131

3232
with pytest.deprecated_call() as record:
3333
deprecation('Deprecated call', [])

python/ipywidgets/ipywidgets/widgets/tests/test_widget.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
from ..widget import Widget
1414
from ..widget_button import Button
1515

16-
PYTEST_PATH = inspect.getfile(pytest.Function)
17-
1816
def test_no_widget_view():
1917
# ensure IPython shell is instantiated
2018
# otherwise display() just calls print
@@ -73,5 +71,6 @@ def test_compatibility():
7371
Widget.close_all()
7472
assert not widget.Widget.widgets
7573
assert not widget.Widget._active_widgets
76-
assert all(x.filename == PYTEST_PATH for x in record)
74+
caller_path = inspect.stack(context=0)[1].filename
75+
assert all(x.filename == caller_path for x in record)
7776
assert len(record) == 6

python/ipywidgets/ipywidgets/widgets/tests/test_widget_button.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
import pytest
66
from ipywidgets import Button
77

8-
PYTEST_PATH = inspect.getfile(pytest.Function)
9-
108
def test_deprecation_fa_icons():
119
with pytest.deprecated_call() as record:
1210
Button(icon='fa-home')
1311
assert len(record) == 1
14-
assert record[0].filename == PYTEST_PATH
12+
assert record[0].filename == inspect.stack(context=0)[1].filename

python/ipywidgets/ipywidgets/widgets/tests/test_widget_string.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@
66

77
from ..widget_string import Combobox, Text
88

9-
10-
PYTEST_PATH = inspect.getfile(pytest.Function)
11-
12-
13-
149
def test_combobox_creation_blank():
1510
w = Combobox()
1611
assert w.value == ''
@@ -41,29 +36,30 @@ def test_combobox_creation_kwargs():
4136
assert w.ensure_option == True
4237

4338
def test_tooltip_deprecation():
39+
caller_path = inspect.stack(context=0)[1].filename
4440
with pytest.deprecated_call() as record:
4541
w = Text(description_tooltip="testing")
4642
assert len(record) == 1
47-
assert record[0].filename == PYTEST_PATH
43+
assert record[0].filename == caller_path
4844

4945
with pytest.deprecated_call() as record:
5046
w.description_tooltip
5147
assert len(record) == 1
52-
assert record[0].filename == PYTEST_PATH
48+
assert record[0].filename == caller_path
5349

5450
with pytest.deprecated_call() as record:
5551
w.description_tooltip == "testing"
5652
assert len(record) == 1
57-
assert record[0].filename == PYTEST_PATH
53+
assert record[0].filename == caller_path
5854

5955
with pytest.deprecated_call() as record:
6056
w.description_tooltip = "second value"
6157
assert len(record) == 1
62-
assert record[0].filename == PYTEST_PATH
58+
assert record[0].filename == caller_path
6359
assert w.tooltip == "second value"
6460

6561
def test_on_submit_deprecation():
6662
with pytest.deprecated_call() as record:
6763
Text().on_submit(lambda *args: ...)
6864
assert len(record) == 1
69-
assert record[0].filename == PYTEST_PATH
65+
assert record[0].filename == inspect.stack(context=0)[1].filename

0 commit comments

Comments
 (0)