Skip to content

Commit d7d4380

Browse files
committed
added test for version warning
1 parent 66b9985 commit d7d4380

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

tests/test_version_warnings.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import importlib
16+
import sys
17+
import warnings
18+
from unittest import mock
19+
20+
import pytest
21+
22+
import google.auth
23+
import google.oauth2
24+
25+
26+
@pytest.mark.parametrize("module", [google.auth, google.oauth2])
27+
@pytest.mark.parametrize(
28+
"version, expected_warning",
29+
[
30+
((3, 8), True),
31+
((3, 9), True),
32+
((3, 10), False),
33+
((3, 13), False),
34+
],
35+
)
36+
def test_python_version_warnings(module, version, expected_warning):
37+
# Mock sys.version_info
38+
# We use a MagicMock that has major and minor attributes
39+
mock_version = mock.Mock()
40+
mock_version.major = version[0]
41+
mock_version.minor = version[1]
42+
43+
with mock.patch.object(sys, "version_info", mock_version):
44+
with warnings.catch_warnings(record=True) as caught_warnings:
45+
warnings.simplefilter("always")
46+
importlib.reload(module)
47+
48+
future_warnings = [
49+
w
50+
for w in caught_warnings
51+
if issubclass(w.category, FutureWarning)
52+
and "past its end of life" in str(w.message)
53+
]
54+
55+
if expected_warning:
56+
assert (
57+
len(future_warnings) > 0
58+
), f"Expected FutureWarning for Python {version} in {module.__name__}"
59+
assert str(version[1]) in str(future_warnings[0].message)
60+
else:
61+
assert (
62+
len(future_warnings) == 0
63+
), f"Did not expect FutureWarning for Python {version} in {module.__name__}"

0 commit comments

Comments
 (0)