Skip to content

Commit 5c78ac9

Browse files
ohmayrgcf-owl-bot[bot]parthea
authored
test: add type flaky to unit test (#1297)
Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: Anthonios Partheniou <partheniou@google.com>
1 parent cdaf6e9 commit 5c78ac9

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

noxfile.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@
5555
UNIT_TEST_EXTERNAL_DEPENDENCIES: List[str] = []
5656
UNIT_TEST_LOCAL_DEPENDENCIES: List[str] = []
5757
UNIT_TEST_DEPENDENCIES: List[str] = []
58-
UNIT_TEST_EXTRAS: List[str] = []
58+
UNIT_TEST_EXTRAS: List[str] = [
59+
"flaky",
60+
]
5961
UNIT_TEST_EXTRAS_BY_PYTHON: Dict[str, List[str]] = {}
6062

6163
SYSTEM_TEST_PYTHON_VERSIONS: List[str] = ["3.12"]

owlbot.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@
337337
cov_level=100,
338338
versions=gcp.common.detect_versions(path="./google", default_first=True),
339339
unit_test_python_versions=["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"],
340+
unit_test_extras=["flaky"],
340341
system_test_python_versions=["3.12"],
341342
system_test_external_dependencies=["psutil","flaky"],
342343
)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"opentelemetry-sdk <= 1.22.0; python_version<='3.7'",
5151
"opentelemetry-sdk >= 1.27.0; python_version>='3.8'",
5252
]
53-
extras = {"libcst": "libcst >= 0.3.10"}
53+
extras = {"libcst": "libcst >= 0.3.10,", "flaky": "flaky"}
5454
url = "https://github.com/googleapis/python-pubsub"
5555

5656
package_root = os.path.abspath(os.path.dirname(__file__))

tests/unit/pubsub_v1/publisher/test_publisher_client.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828

2929
import pytest
3030
import time
31+
from flaky import flaky
32+
from typing import cast, Callable, Any, TypeVar
3133

3234
from opentelemetry import trace
3335
from google.api_core import gapic_v1
@@ -49,6 +51,10 @@
4951
)
5052

5153

54+
C = TypeVar("C", bound=Callable[..., Any])
55+
typed_flaky = cast(Callable[[C], C], flaky(max_runs=5, min_passes=1))
56+
57+
5258
def _assert_retries_equal(retry, retry2):
5359
# Retry instances cannot be directly compared, because their predicates are
5460
# different instances of the same function. We thus manually compare their other
@@ -142,6 +148,7 @@ def test_init_w_custom_transport(creds):
142148
False,
143149
],
144150
)
151+
@typed_flaky
145152
def test_open_telemetry_publisher_options(creds, enable_open_telemetry):
146153
if sys.version_info >= (3, 8) or enable_open_telemetry is False:
147154
client = publisher.Client(

0 commit comments

Comments
 (0)