Time Travel with Python
The blog post discusses testing time-based functionality in software development, emphasizing the importance of accurate time-based tests for applications across time zones and daylight-saving changes. It introduces Python testing methods using unittest.mock and Freezegun for robust time manipulation.
Read original articleIn the blog post "Time travel with Python" from fq.nz, the importance of testing time-based functionality in software development is highlighted. The article discusses the need for time-based tests to ensure applications work correctly across different time zones and changes like daylight-saving time. It introduces methods to test time-based logic in Python, focusing on the use of unittest.mock to patch datetime and the third-party library Freezegun for more robust time manipulation in tests. Examples of code snippets for testing a function that checks if it's New Year's Day are provided using both unittest.mock and Freezegun approaches. The blog concludes by emphasizing the versatility of Freezegun for time travel testing in Python, offering a more comprehensive solution compared to unittest.mock, especially for complex applications. Readers are encouraged to explore these testing techniques to ensure the accuracy of time-dependent features in their Python projects.
Related
What's up Python? Django get background tasks, a new REPL, bye bye gunicorn
Several Python updates include Django's background task integration, a new lightweight Python REPL, Uvicorn's multiprocessing support, and PyPI blocking outlook.com emails to combat bot registrations, enhancing Python development and security.
Python Modern Practices
Python development best practices involve using tools like mise or pyenv for multiple versions, latest Python version, pipx for app running. Project tips include src layout, pyproject.toml, virtual environments, Black, flake8, pytest, wheel, type hinting, f-strings, datetime, enum, Named Tuples, data classes, breakpoint(), logging, TOML config for efficiency and maintainability.
Summary of Major Changes Between Python Versions
The article details Python updates from versions 3.7 to 3.12, highlighting async/await, Walrus operator, Type hints, F-strings, Assignment expressions, Typing enhancements, Structural Pattern Matching, Tomllib, and useful tools.
Making Python Less Random
Andrew Healey detailed his debugging journey with a Python game prototype facing randomness issues. He used ptrace to control system calls, ensuring consistent results without changing the code, showcasing advanced system call tracing techniques.
Making Python Less Random
Andrew Healey discussed debugging a Python game prototype with randomness bugs. He used ptrace to control system calls, ensuring consistent results for random functions without altering the code, enabling deterministic debugging.
Related
What's up Python? Django get background tasks, a new REPL, bye bye gunicorn
Several Python updates include Django's background task integration, a new lightweight Python REPL, Uvicorn's multiprocessing support, and PyPI blocking outlook.com emails to combat bot registrations, enhancing Python development and security.
Python Modern Practices
Python development best practices involve using tools like mise or pyenv for multiple versions, latest Python version, pipx for app running. Project tips include src layout, pyproject.toml, virtual environments, Black, flake8, pytest, wheel, type hinting, f-strings, datetime, enum, Named Tuples, data classes, breakpoint(), logging, TOML config for efficiency and maintainability.
Summary of Major Changes Between Python Versions
The article details Python updates from versions 3.7 to 3.12, highlighting async/await, Walrus operator, Type hints, F-strings, Assignment expressions, Typing enhancements, Structural Pattern Matching, Tomllib, and useful tools.
Making Python Less Random
Andrew Healey detailed his debugging journey with a Python game prototype facing randomness issues. He used ptrace to control system calls, ensuring consistent results without changing the code, showcasing advanced system call tracing techniques.
Making Python Less Random
Andrew Healey discussed debugging a Python game prototype with randomness bugs. He used ptrace to control system calls, ensuring consistent results for random functions without altering the code, enabling deterministic debugging.