time-machine versus freezegun, a benchmark

I wrote my library time-machine last year as a way to speed up tests that need to accurately mock the current time.
Read more...I wrote my library time-machine last year as a way to speed up tests that need to accurately mock the current time.
Read more...For all my linting needs these days I use the pre-commit framework. It has integrations with every tool I want to use, and uses Git’s hooks to prevent non-passing code from ever being committed.
Read more...I recently optimized a client project’s test suite, and in the process found a test whose runtime had crept up ever since it had been written. The problematic test exercised an import process from a fixed past date until the current day. The test’s runtime therefore grew every day, until it reached over a minute.
Read more...If you’re testing Python code that relies on the current date or time, you will probably want to mock time to test different scenarios. For example, what happens when you run a certain piece of code on February 29? (A common source of bugs.)
Read more...Earlier this week I tweeted about my two part offer on my book Speed Up Your Django Tests for this year’s Cyber Monday.
Read more...Sometimes tests need to change environment variables.
This is fairly straightforward in tests using Python’s unittest
, thanks to os.environ
quacking like a dict
, and the unittest.mock.patch.dict
decorator/context manager.
Sometimes tests need to change environment variables.
This is fairly straightforward in pytest, thanks to os.environ
quacking like a dict
, and the unittest.mock.patch.dict
decorator/context manager.