Skip to content

Commit 14a5978

Browse files
authored
fix: fix async tests and round-off error in test expectations (#837)
* fix: properly designate async test methods * fix: fix async tests * fix: made additional test be an async method
1 parent 2c98385 commit 14a5978

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

tests/asyncio/gapic/test_method_async.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,11 @@ async def test_wrap_method_with_overriding_timeout_as_a_number():
256256
result = await wrapped_method(timeout=22)
257257

258258
assert result == 42
259-
method.assert_called_once_with(timeout=22, metadata=mock.ANY)
259+
260+
actual_timeout = method.call_args[1]["timeout"]
261+
metadata = method.call_args[1]["metadata"]
262+
assert metadata == mock.ANY
263+
assert actual_timeout == pytest.approx(22, abs=0.01)
260264

261265

262266
@pytest.mark.asyncio

tests/asyncio/test_operation_async.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ async def test_constructor():
8585

8686

8787
@pytest.mark.asyncio
88-
def test_metadata():
88+
async def test_metadata():
8989
expected_metadata = struct_pb2.Struct()
9090
future, _, _ = make_operation_future(
9191
[make_operation_proto(metadata=expected_metadata)]
@@ -178,7 +178,7 @@ async def test_unexpected_result(unused_sleep):
178178

179179

180180
@pytest.mark.asyncio
181-
def test_from_gapic():
181+
async def test_from_gapic():
182182
operation_proto = make_operation_proto(done=True)
183183
operations_client = mock.create_autospec(
184184
operations_v1.OperationsClient, instance=True

tests/unit/gapic/test_method.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,11 @@ def test_wrap_method_with_overriding_timeout_as_a_number():
201201
result = wrapped_method(timeout=22)
202202

203203
assert result == 42
204-
method.assert_called_once_with(timeout=22, metadata=mock.ANY)
204+
205+
actual_timeout = method.call_args[1]["timeout"]
206+
metadata = method.call_args[1]["metadata"]
207+
assert metadata == mock.ANY
208+
assert actual_timeout == pytest.approx(22, abs=0.01)
205209

206210

207211
def test_wrap_method_with_call():

0 commit comments

Comments
 (0)