Til

Django Testing: Dynamically Accessing Attributes in Unit Tests

In this blog post, we’ll explore a way to write unit tests for a Django model using Model Mommy. Our main focus is on the update_dog_from_data function, which updates a Dog object with JSON data. However, the highlight is the technique to dynamically access attribute values in the tested object. By the end, you’ll learn some unit testing strategies and gain insights into dynamically interacting with object attributes during testing.

TIL: time travel with Python’s standard library

There are a few different approaches for writing tests for date and/or time-sensitive functionality.

One could choose to add a sleep() in the test, which would guarantee that the time passed, but that also has the downside of increasing the run time of the test.

TIL: installed packages in Python – list, and show

If your Python project has a very short list of required packages (in requirements, pipfile, etc), it’s easy to see all packages you have. But on large projects, the dependencies can run pretty long, not to mention the dependencies for the required packages. And what about learning more about those dependencies?

Find the commit that introduced a bug in your code: how to use git bisect in 7 steps

When I first heard about git bisect I thought it sounded scary and complicated, so I never looked for an opportunity to learn more about it and use it. That’s until last week when I ran into a bug in our master branch. I knew that the bug was not there two days before so I tested an earlier commit and confirmed that that older commit was a good one. Now, we had tens of commits in between. How to find out when exactly the bug was introduced? It would be impractical to check and test each individual commit.