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.
This commit is contained in:
efokschaner 2022-04-30 15:11:21 -07:00 committed by GitHub
parent 6a70b8e8ea
commit 06c26ba60d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -177,15 +177,16 @@ async def test_service_call_lower_level_with_overrides():
@pytest.mark.asyncio
@pytest.mark.parametrize(
("overrides",),
("overrides_gen",),
[
(dict(timeout=10),),
(dict(deadline=grpclib.metadata.Deadline.from_timeout(10)),),
(dict(metadata={"authorization": str(uuid.uuid4())}),),
(dict(timeout=20, metadata={"authorization": str(uuid.uuid4())}),),
(lambda: dict(timeout=10),),
(lambda: dict(deadline=grpclib.metadata.Deadline.from_timeout(10)),),
(lambda: dict(metadata={"authorization": str(uuid.uuid4())}),),
(lambda: dict(timeout=20, metadata={"authorization": str(uuid.uuid4())}),),
],
)
async def test_service_call_high_level_with_overrides(mocker, overrides):
async def test_service_call_high_level_with_overrides(mocker, overrides_gen):
overrides = overrides_gen()
request_spy = mocker.spy(grpclib.client.Channel, "request")
name = str(uuid.uuid4())
defaults = dict(