| 
18 | 18 | 
 
  | 
19 | 19 | import warnings  | 
20 | 20 | 
 
  | 
 | 21 | +import pytest  | 
 | 22 | + | 
21 | 23 | from elasticsearch._sync.client.utils import Stability, _quote, _stability_warning  | 
22 | 24 | from elasticsearch.exceptions import GeneralAvailabilityWarning  | 
23 | 25 | 
 
  | 
@@ -58,26 +60,20 @@ def test_beta(self, recwarn):  | 
58 | 60 |         def func_beta(*args, **kwargs):  | 
59 | 61 |             pass  | 
60 | 62 | 
 
  | 
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()  | 
69 | 68 | 
 
  | 
70 | 69 |     def test_experimental(self, recwarn):  | 
71 | 70 | 
 
  | 
72 | 71 |         @_stability_warning(stability=Stability.EXPERIMENTAL)  | 
73 | 72 |         def func_experimental(*args, **kwargs):  | 
74 | 73 |             pass  | 
75 | 74 | 
 
  | 
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