question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Testing asyncio code made harder due to freezing time.monotonic()

See original GitHub issue

Hi,

Version 1.1.0 makes it harder to test asyncio-based code relying on asyncio.sleep(), asyncio.wait_for(), … where what we only want to test is datetime related. In such cases, without any auto or manual ticking all time based awaits simply freeze because : The event loop has its own internal clock for computing timeouts. Which clock is used depends on the (platform-specific) event loop implementation; ideally it is a monotonic clock. This will generally be a different clock than time.time(). (See https://docs.python.org/3.6/library/asyncio-eventloop.html#asyncio-delayed-calls).

Would it be possible to make time.monotonic() freezing optional?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

1reaction
romainletendartcommented, Jan 21, 2021

That indeed did the trick for me:

with freezegun.freeze_time(dt, ignore=['asyncio']):
    # asyncio time-based code

Thank you very much!

0reactions
boxedcommented, Jan 21, 2021

That good but I don’t think this means we should close the ticket? The question is if freezegun needs to have this in the ignore list or not. I don’t think it’s obvious.

Could you maybe show a minimal program that shows this issue? I think this would help me understand if freezegun needs to be changed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Help with asyncio program freezing during requests - Async-SIG
I'm trying to write a program to grab multiple files over http. I'm writing it using asyncio (with httpx as the HTTP library)...
Read more >
Advanced asyncio testing - Stefan Scherfke
While I was working on that articel, Tin Tvrtkovic created the plug-in pytest-asyncio. In short, it lets you do this: import asyncio import...
Read more >
Cooperative Multitasking in CircuitPython with asyncio
We looked at how MicroPython supports hardware interrupts and decided that the restrictions that are imposed make it harder to use and more ......
Read more >
Testing asyncio code – roguelynn - Lynn Root
We want to update the testing event loop so we can override the close() behavior, which gets called in our main function.
Read more >
Unit Testing Python Asyncio Code | cloudfit-public-docs
Notice that the type returned from the call to my_mock() is a coroutine, which must be awaited to produce a result, as in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found