|
18 | 18 |
|
19 | 19 | import warnings |
20 | 20 |
|
| 21 | +import pytest |
| 22 | + |
21 | 23 | from elasticsearch_serverless._sync.client.utils import ( |
22 | 24 | Stability, |
23 | 25 | _quote, |
@@ -62,43 +64,20 @@ def test_beta(self, recwarn): |
62 | 64 | def func_beta(*args, **kwargs): |
63 | 65 | pass |
64 | 66 |
|
65 | | - func_beta() |
66 | | - |
67 | | - assert len(recwarn) == 1 |
68 | | - user_warning = recwarn.pop(GeneralAvailabilityWarning) |
69 | | - assert user_warning.category == GeneralAvailabilityWarning |
70 | | - assert user_warning.message.args[0].startswith( |
71 | | - "This API is in beta and is subject to change." |
72 | | - ) |
| 67 | + with pytest.warns( |
| 68 | + GeneralAvailabilityWarning, |
| 69 | + match="This API is in beta and is subject to change.", |
| 70 | + ): |
| 71 | + func_beta() |
73 | 72 |
|
74 | 73 | def test_experimental(self, recwarn): |
75 | 74 |
|
76 | 75 | @_stability_warning(stability=Stability.EXPERIMENTAL) |
77 | 76 | def func_experimental(*args, **kwargs): |
78 | 77 | pass |
79 | 78 |
|
80 | | - func_experimental() |
81 | | - |
82 | | - assert len(recwarn) == 1 |
83 | | - user_warning = recwarn.pop(GeneralAvailabilityWarning) |
84 | | - assert user_warning.category == GeneralAvailabilityWarning |
85 | | - assert user_warning.message.args[0].startswith( |
86 | | - "This API is in technical preview and may be changed or removed in a future release." |
87 | | - ) |
88 | | - |
89 | | - def test_deprecated(self, recwarn): |
90 | | - |
91 | | - @_stability_warning( |
92 | | - stability=Stability.DEPRECATED, version="8.4.0", message="Use bar instead." |
93 | | - ) |
94 | | - def func_deprecated(*args, **kwargs): |
95 | | - pass |
96 | | - |
97 | | - func_deprecated() |
98 | | - |
99 | | - assert len(recwarn) == 1 |
100 | | - user_warning = recwarn.pop(DeprecationWarning) |
101 | | - assert user_warning.category == DeprecationWarning |
102 | | - assert user_warning.message.args[0] == ( |
103 | | - "This API was deprecated in Elasticsearch 8.4.0. Use bar instead." |
104 | | - ) |
| 79 | + with pytest.warns( |
| 80 | + GeneralAvailabilityWarning, |
| 81 | + match="This API is in technical preview and may be changed or removed in a future release.", |
| 82 | + ): |
| 83 | + func_experimental() |
0 commit comments