Skip to content

Commit 317df99

Browse files
committed
Switch to pytest.warns to not catch unrelated warnings
1 parent fdc87c6 commit 317df99

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

test_elasticsearch/test_client/test_utils.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import warnings
2020

21+
import pytest
22+
2123
from elasticsearch._sync.client.utils import Stability, _quote, _stability_warning
2224
from elasticsearch.exceptions import GeneralAvailabilityWarning
2325

@@ -58,26 +60,20 @@ def test_beta(self, recwarn):
5860
def func_beta(*args, **kwargs):
5961
pass
6062

61-
func_beta()
62-
63-
assert len(recwarn) == 1, [w.message for w in recwarn]
64-
user_warning = recwarn.pop(GeneralAvailabilityWarning)
65-
assert user_warning.category == GeneralAvailabilityWarning
66-
assert user_warning.message.args[0].startswith(
67-
"This API is in beta and is subject to change."
68-
)
63+
with pytest.warns(
64+
GeneralAvailabilityWarning,
65+
match="This API is in beta and is subject to change.",
66+
):
67+
func_beta()
6968

7069
def test_experimental(self, recwarn):
7170

7271
@_stability_warning(stability=Stability.EXPERIMENTAL)
7372
def func_experimental(*args, **kwargs):
7473
pass
7574

76-
func_experimental()
77-
78-
assert len(recwarn) == 1, [w.message for w in recwarn]
79-
user_warning = recwarn.pop(GeneralAvailabilityWarning)
80-
assert user_warning.category == GeneralAvailabilityWarning
81-
assert user_warning.message.args[0].startswith(
82-
"This API is in technical preview and may be changed or removed in a future release."
83-
)
75+
with pytest.warns(
76+
GeneralAvailabilityWarning,
77+
match="This API is in technical preview and may be changed or removed in a future release.",
78+
):
79+
func_experimental()

0 commit comments

Comments
 (0)