Skip to content

Commit 46e8789

Browse files
build: treat warnings as errors (#564)
* build: treat warnings as errors * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * lint * add pytest.ini * add line break * filter warning which appears only in python 3.7 * filter deprecation warning for grpcio-gcp --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 42e8b6e commit 46e8789

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

pytest.ini

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[pytest]
2+
filterwarnings =
3+
# treat all warnings as errors
4+
error
5+
# Remove once https://github.com/pytest-dev/pytest-cov/issues/621 is fixed
6+
ignore:.*The --rsyncdir command line argument and rsyncdirs config variable are deprecated:DeprecationWarning
7+
# Remove once https://github.com/protocolbuffers/protobuf/issues/12186 is fixed
8+
ignore:.*custom tp_new.*in Python 3.14:DeprecationWarning
9+
# Remove once support for python 3.7 is dropped
10+
# This warning only appears when using python 3.7
11+
ignore:.*Using or importing the ABCs from.*collections:DeprecationWarning
12+
# Remove once support for grpcio-gcp is deprecated
13+
# See https://github.com/googleapis/python-api-core/blob/42e8b6e6f426cab749b34906529e8aaf3f133d75/google/api_core/grpc_helpers.py#L39-L45
14+
ignore:.*Support for grpcio-gcp is deprecated:DeprecationWarning
15+
# Remove once https://github.com/googleapis/python-api-common-protos/pull/187/files is merged
16+
ignore:.*pkg_resources.declare_namespace:DeprecationWarning
17+
ignore:.*pkg_resources is deprecated as an API:DeprecationWarning
18+
# Remove once release PR https://github.com/googleapis/proto-plus-python/pull/391 is merged
19+
ignore:datetime.datetime.utcfromtimestamp\(\) is deprecated:DeprecationWarning:proto.datetime_helpers
20+
# Remove once https://github.com/grpc/grpc/issues/35086 is fixed
21+
ignore:There is no current event loop:DeprecationWarning

tests/unit/test_iam.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,15 @@ def test_owners_getter(self):
167167
assert policy.owners == expected
168168

169169
def test_owners_setter(self):
170-
import warnings
171170
from google.api_core.iam import OWNER_ROLE
172171

173172
MEMBER = "user:phred@example.com"
174173
expected = set([MEMBER])
175174
policy = self._make_one()
176175

177-
with warnings.catch_warnings(record=True) as warned:
176+
with pytest.warns(
177+
DeprecationWarning, match="Assigning to 'owners' is deprecated."
178+
) as warned:
178179
policy.owners = [MEMBER]
179180

180181
(warning,) = warned
@@ -191,14 +192,15 @@ def test_editors_getter(self):
191192
assert policy.editors == expected
192193

193194
def test_editors_setter(self):
194-
import warnings
195195
from google.api_core.iam import EDITOR_ROLE
196196

197197
MEMBER = "user:phred@example.com"
198198
expected = set([MEMBER])
199199
policy = self._make_one()
200200

201-
with warnings.catch_warnings(record=True) as warned:
201+
with pytest.warns(
202+
DeprecationWarning, match="Assigning to 'editors' is deprecated."
203+
) as warned:
202204
policy.editors = [MEMBER]
203205

204206
(warning,) = warned
@@ -215,14 +217,15 @@ def test_viewers_getter(self):
215217
assert policy.viewers == expected
216218

217219
def test_viewers_setter(self):
218-
import warnings
219220
from google.api_core.iam import VIEWER_ROLE
220221

221222
MEMBER = "user:phred@example.com"
222223
expected = set([MEMBER])
223224
policy = self._make_one()
224225

225-
with warnings.catch_warnings(record=True) as warned:
226+
with pytest.warns(
227+
DeprecationWarning, match="Assigning to 'viewers' is deprecated."
228+
) as warned:
226229
policy.viewers = [MEMBER]
227230

228231
(warning,) = warned
@@ -337,12 +340,13 @@ def test_to_api_repr_binding_wo_members(self):
337340
assert policy.to_api_repr() == {}
338341

339342
def test_to_api_repr_binding_w_duplicates(self):
340-
import warnings
341343
from google.api_core.iam import OWNER_ROLE
342344

343345
OWNER = "group:cloud-logs@google.com"
344346
policy = self._make_one()
345-
with warnings.catch_warnings(record=True):
347+
with pytest.warns(
348+
DeprecationWarning, match="Assigning to 'owners' is deprecated."
349+
):
346350
policy.owners = [OWNER, OWNER]
347351
assert policy.to_api_repr() == {
348352
"bindings": [{"role": OWNER_ROLE, "members": [OWNER]}]

0 commit comments

Comments
 (0)