time.sleep
A function in the time module that pauses the program for a given number of seconds, which may be a fraction.
In more detail
time.sleep(0.05) pauses for a twentieth of a second, and the calling thread does nothing else during the pause. Sleeping in a test to wait for something makes it slower but not reliable, because the thing may still not be ready. Wait for an explicit readiness condition instead.
Related terms
- animation — Making shapes appear to move by redrawing them in slightly different places many times a second.
- import statement — A statement that makes code from another module or package available by name in the current file.
- flaky test — A test that sometimes passes and sometimes fails on the same code, because it depends on something it does not control.
- frozen time — Making the current time a fixed value during a test, by passing an instant in or patching the clock.
- health check — A regular automated test of whether a program or service is working, such as a request to its health endpoint or a command run inside its container.
Taught in
- Animation: Moving One Shape — Hands-on Python: Complete Video Course & Book
- Animation: Loops, Bouncing, Flushing — Hands-on Python: Complete Video Course & Book
- Colours, Custom And Random — Hands-on Python: Complete Video Course & Book
- Graphical Applications With While — Hands-on Python: Complete Video Course & Book
- The Test Pyramid And Where It Is Wrong — Automated Testing, TDD & Quality Engineering
- Testing Time And Randomness — Automated Testing, TDD & Quality Engineering
- Integration Testing With Containers — Automated Testing, TDD & Quality Engineering