Skip to content

Commit 0ba8220

Browse files
authored
build: treat warnings as errors (#819)
* build: treat warnings as errors * resolve warning Client.dataset is deprecated and will be removed in a future version * See #820 * address warning @pytest.yield_fixture is deprecated. Use @pytest.fixture instead; they are the same. * filter warnings from grpcio * revert * update comment
1 parent d3dc2ac commit 0ba8220

File tree

5 files changed

+71
-10
lines changed

5 files changed

+71
-10
lines changed

pytest.ini

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[pytest]
2+
filterwarnings =
3+
# treat all warnings as errors
4+
error
5+
# Remove once https://github.com/protocolbuffers/protobuf/issues/12186 is fixed
6+
ignore:.*custom tp_new.*in Python 3.14:DeprecationWarning
7+
# Remove once Release PR https://github.com/googleapis/python-api-common-protos/pull/191 is merged
8+
ignore:.*pkg_resources.declare_namespace:DeprecationWarning
9+
ignore:.*pkg_resources is deprecated as an API:DeprecationWarning
10+
# Remove once https://github.com/grpc/grpc/issues/35086 is fixed
11+
ignore:There is no current event loop:DeprecationWarning:grpc.aio._channel
12+
# Remove once release PR https://github.com/googleapis/proto-plus-python/pull/391 is merged
13+
ignore:datetime.datetime.utcfromtimestamp\(\) is deprecated:DeprecationWarning:proto.datetime_helpers
14+
# Remove once release PR https://github.com/googleapis/python-api-core/pull/555 is merged
15+
ignore:datetime.datetime.utcnow\(\) is deprecated:DeprecationWarning:google.api_core.datetime_helpers
16+
# Remove once https://github.com/googleapis/python-logging/issues/818 is fixed
17+
ignore:datetime.datetime.utcfromtimestamp\(\) is deprecated:DeprecationWarning:google.cloud.logging_v2.handlers.transports
18+
ignore:datetime.datetime.utcnow\(\) is deprecated:DeprecationWarning:tests.unit.test__http
19+
ignore:datetime.datetime.utcnow\(\) is deprecated:DeprecationWarning:tests.unit.test_entries
20+
# Remove once https://github.com/googleapis/python-logging/issues/820 is fixed
21+
ignore:.*warn.*is deprecated, use.*warning.*instead:DeprecationWarning
22+
# Remove once a version of grpcio newer than 1.59.3 is released to PyPI
23+
ignore:datetime.datetime.utcnow\(\) is deprecated:DeprecationWarning:grpc._channel

samples/snippets/export_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def _random_id():
3434
)
3535

3636

37-
@pytest.yield_fixture
37+
@pytest.fixture
3838
def example_sink():
3939
client = logging.Client()
4040

tests/system/test_system.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ def _init_bigquery_dataset(self):
813813
# Stackdriver Logging to write into it.
814814
retry = RetryErrors((TooManyRequests, BadGateway, ServiceUnavailable))
815815
bigquery_client = bigquery.Client()
816-
dataset_ref = bigquery_client.dataset(dataset_name)
816+
dataset_ref = bigquery.DatasetReference(Config.CLIENT.project, dataset_name)
817817
dataset = retry(bigquery_client.create_dataset)(bigquery.Dataset(dataset_ref))
818818
self.to_delete.append((bigquery_client, dataset))
819819
bigquery_client.get_dataset(dataset)

tests/unit/handlers/test_app_engine.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
import logging
16+
import pytest
1617
import unittest
1718

1819
import mock
@@ -46,6 +47,9 @@ def test_constructor_w_gae_standard_env(self):
4647
), mock.patch(
4748
"google.cloud.logging_v2.handlers._monitored_resources.retrieve_metadata_server",
4849
return_value=self.PROJECT,
50+
), pytest.warns(
51+
DeprecationWarning,
52+
match="AppEngineHandler is deprecated. Use CloudLoggingHandler instead",
4953
):
5054
handler = self._make_one(client, transport=_Transport)
5155

@@ -78,6 +82,9 @@ def test_constructor_w_gae_flex_env(self):
7882
), mock.patch(
7983
"google.cloud.logging_v2.handlers._monitored_resources.retrieve_metadata_server",
8084
return_value=self.PROJECT,
85+
), pytest.warns(
86+
DeprecationWarning,
87+
match="AppEngineHandler is deprecated. Use CloudLoggingHandler instead",
8188
):
8289
handler = self._make_one(
8390
client, name=name, transport=_Transport, stream=stream
@@ -99,7 +106,10 @@ def test_emit(self):
99106
"google.cloud.logging_v2.handlers.app_engine.get_request_data",
100107
return_value=(expected_http_request, trace_id, None, None),
101108
)
102-
with get_request_patch:
109+
with get_request_patch, pytest.warns(
110+
DeprecationWarning,
111+
match="AppEngineHandler is deprecated. Use CloudLoggingHandler instead",
112+
):
103113
# library integrations mocked to return test data
104114
client = mock.Mock(project=self.PROJECT, spec=["project"])
105115
handler = self._make_one(client, transport=_Transport)
@@ -137,7 +147,10 @@ def test_emit_manual_field_override(self):
137147
"google.cloud.logging_v2.handlers.app_engine.get_request_data",
138148
return_value=(inferred_http_request, inferred_trace_id, None, None),
139149
)
140-
with get_request_patch:
150+
with get_request_patch, pytest.warns(
151+
DeprecationWarning,
152+
match="AppEngineHandler is deprecated. Use CloudLoggingHandler instead",
153+
):
141154
# library integrations mocked to return test data
142155
client = mock.Mock(project=self.PROJECT, spec=["project"])
143156
handler = self._make_one(client, transport=_Transport)
@@ -197,12 +210,20 @@ def test_get_gae_labels_with_label(self):
197210
from google.cloud.logging_v2.handlers import app_engine
198211

199212
trace_id = "test-gae-trace-id"
200-
gae_labels = self._get_gae_labels_helper(trace_id)
213+
with pytest.warns(
214+
DeprecationWarning,
215+
match="AppEngineHandler is deprecated. Use CloudLoggingHandler instead",
216+
):
217+
gae_labels = self._get_gae_labels_helper(trace_id)
201218
expected_labels = {app_engine._TRACE_ID_LABEL: trace_id}
202219
self.assertEqual(gae_labels, expected_labels)
203220

204221
def test_get_gae_labels_without_label(self):
205-
gae_labels = self._get_gae_labels_helper(None)
222+
with pytest.warns(
223+
DeprecationWarning,
224+
match="AppEngineHandler is deprecated. Use CloudLoggingHandler instead",
225+
):
226+
gae_labels = self._get_gae_labels_helper(None)
206227
self.assertEqual(gae_labels, {})
207228

208229

tests/unit/handlers/test_container_engine.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import pytest
1516
import unittest
1617

1718

@@ -27,18 +28,30 @@ def _make_one(self, *args, **kw):
2728
return self._get_target_class()(*args, **kw)
2829

2930
def test_ctor_defaults(self):
30-
handler = self._make_one()
31+
with pytest.warns(
32+
DeprecationWarning,
33+
match="ContainerEngineHandler is deprecated. Use StructuredLogHandler instead",
34+
):
35+
handler = self._make_one()
3136
self.assertIsNone(handler.name)
3237

3338
def test_ctor_w_name(self):
34-
handler = self._make_one(name="foo")
39+
with pytest.warns(
40+
DeprecationWarning,
41+
match="ContainerEngineHandler is deprecated. Use StructuredLogHandler instead",
42+
):
43+
handler = self._make_one(name="foo")
3544
self.assertEqual(handler.name, "foo")
3645

3746
def test_format(self):
3847
import logging
3948
import json
4049

41-
handler = self._make_one()
50+
with pytest.warns(
51+
DeprecationWarning,
52+
match="ContainerEngineHandler is deprecated. Use StructuredLogHandler instead",
53+
):
54+
handler = self._make_one()
4255
logname = "loggername"
4356
message = "hello world,嗨 世界"
4457
record = logging.LogRecord(
@@ -51,6 +64,10 @@ def test_format(self):
5164
"thread": record.thread,
5265
"severity": record.levelname,
5366
}
54-
payload = handler.format(record)
67+
with pytest.warns(
68+
DeprecationWarning,
69+
match="format_stackdriver_json is deprecated. Use StructuredLogHandler instead",
70+
):
71+
payload = handler.format(record)
5572

5673
self.assertEqual(payload, json.dumps(expected_payload, ensure_ascii=False))

0 commit comments

Comments
 (0)