Skip to content

Commit

Permalink
test: add type flaky to unit test (#1297)
Browse files Browse the repository at this point in the history
Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Co-authored-by: Anthonios Partheniou <[email protected]>
  • Loading branch information
3 people authored Nov 5, 2024
1 parent cdaf6e9 commit 5c78ac9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
4 changes: 3 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@
UNIT_TEST_EXTERNAL_DEPENDENCIES: List[str] = []
UNIT_TEST_LOCAL_DEPENDENCIES: List[str] = []
UNIT_TEST_DEPENDENCIES: List[str] = []
UNIT_TEST_EXTRAS: List[str] = []
UNIT_TEST_EXTRAS: List[str] = [
"flaky",
]
UNIT_TEST_EXTRAS_BY_PYTHON: Dict[str, List[str]] = {}

SYSTEM_TEST_PYTHON_VERSIONS: List[str] = ["3.12"]
Expand Down
1 change: 1 addition & 0 deletions owlbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@
cov_level=100,
versions=gcp.common.detect_versions(path="./google", default_first=True),
unit_test_python_versions=["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"],
unit_test_extras=["flaky"],
system_test_python_versions=["3.12"],
system_test_external_dependencies=["psutil","flaky"],
)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"opentelemetry-sdk <= 1.22.0; python_version<='3.7'",
"opentelemetry-sdk >= 1.27.0; python_version>='3.8'",
]
extras = {"libcst": "libcst >= 0.3.10"}
extras = {"libcst": "libcst >= 0.3.10,", "flaky": "flaky"}
url = "https://github.com/googleapis/python-pubsub"

package_root = os.path.abspath(os.path.dirname(__file__))
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/pubsub_v1/publisher/test_publisher_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

import pytest
import time
from flaky import flaky
from typing import cast, Callable, Any, TypeVar

from opentelemetry import trace
from google.api_core import gapic_v1
Expand All @@ -49,6 +51,10 @@
)


C = TypeVar("C", bound=Callable[..., Any])
typed_flaky = cast(Callable[[C], C], flaky(max_runs=5, min_passes=1))


def _assert_retries_equal(retry, retry2):
# Retry instances cannot be directly compared, because their predicates are
# different instances of the same function. We thus manually compare their other
Expand Down Expand Up @@ -142,6 +148,7 @@ def test_init_w_custom_transport(creds):
False,
],
)
@typed_flaky
def test_open_telemetry_publisher_options(creds, enable_open_telemetry):
if sys.version_info >= (3, 8) or enable_open_telemetry is False:
client = publisher.Client(
Expand Down

0 comments on commit 5c78ac9

Please sign in to comment.