Break trio loop in pytest tests

63 views Asked by At

I need to override response for some my tests. I use pytest+ selenium. I found an example of code that can be used for that, it override response using selenium cdp and trio, also I add pytest-trio to make it work. Here is the code example:

class TestBiddersSelect:
    async def cpd(self):
         async with self.driver.bidi_connection() as connection:
            session, devtools = connection.session, connection.devtools
            await session.execute(devtools.fetch.enable())
            listener = session.listen(devtools.fetch.RequestPaused)
            async with trio.open_nursery() as nursery:
                async for event in listener:
                    if "url_example" in str(event.request.url) and event.request.method == "GET":
                        # override response
    async test_override(self):
        await self.cdp()

The problem is that the async for event in listener iterator does not stop, so the test does not complete.

Perhaps someone knows how this can be solved or can give an example of a different approach. Thanks

0

There are 0 answers