Skip to content

Commit 06c26ba

Browse files
authored
tests: Lazy evaluate Deadline parameter in pytest (#380)
The pytest parameters are evaluated when the tests are loading. The Deadline.from_timeout is a fixed point in time. By deferring the evaluation it helps ensure that the deadline is not reached before the test is executed.
1 parent 6a70b8e commit 06c26ba

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

tests/grpc/test_grpclib_client.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,16 @@ async def test_service_call_lower_level_with_overrides():
177177

178178
@pytest.mark.asyncio
179179
@pytest.mark.parametrize(
180-
("overrides",),
180+
("overrides_gen",),
181181
[
182-
(dict(timeout=10),),
183-
(dict(deadline=grpclib.metadata.Deadline.from_timeout(10)),),
184-
(dict(metadata={"authorization": str(uuid.uuid4())}),),
185-
(dict(timeout=20, metadata={"authorization": str(uuid.uuid4())}),),
182+
(lambda: dict(timeout=10),),
183+
(lambda: dict(deadline=grpclib.metadata.Deadline.from_timeout(10)),),
184+
(lambda: dict(metadata={"authorization": str(uuid.uuid4())}),),
185+
(lambda: dict(timeout=20, metadata={"authorization": str(uuid.uuid4())}),),
186186
],
187187
)
188-
async def test_service_call_high_level_with_overrides(mocker, overrides):
188+
async def test_service_call_high_level_with_overrides(mocker, overrides_gen):
189+
overrides = overrides_gen()
189190
request_spy = mocker.spy(grpclib.client.Channel, "request")
190191
name = str(uuid.uuid4())
191192
defaults = dict(

0 commit comments

Comments
 (0)