Python Testing Tips2024-02-14T13:56:59+00:00

Python Testing Tips

Take your skills to the next level

2711, 2025

Time Travel in Your Tests with freezegun

Testing time-dependent code is notoriously tricky. If your code checks whether a subscription is active, validates trial eligibility, or performs any date calculations, your tests can become flaky and unreliable. Enter freezegun - a library that lets you freeze

1609, 2025

How to customize assertion error message

Many times, it's hard to understand why a test is failing just by reading the assertion error. For example, when writing end-to-end tests and asserting the expected status code. Without a custom message, you'll know only that the API

304, 2025

Name parameterized pytest examples

Text parametrization is a great feature provided by pytest. We've touched it inside the Parametrize tests using pytest article. Anyhow, it's also easy to make things unreadable when there are lots of examples or lots of parametrized values. We want

502, 2025

Parametrize tests using pytest

The goal of tests is to make sure that our software is working as expected. Sometimes, it's enough to use a single example to prove that things meet our expectations. For example, when testing, we can fetch a user

1004, 2024

Testing behavior, not implementation details – part 3

One of the properties of a valuable test is that it's fast. While tests with a database might be fast enough for simple projects, their execution times quickly add up. As mentioned in "Running tests in parallel with pytest", you

2703, 2024

Testing behavior, not implementation details – part 2

In "Testing Behavior, not implementation details - part 1", we've briefly touched on the term observable behavior. But what is observable behavior anyway? Explaining this as "whatever you see software doing" doesn't help much. Especially not when we are talking

1203, 2024

Running tests in parallel with pytest

Running tests takes time. Even if they are insanely fast. The execution time adds up once you add more and more tests to your project. You might not notice that when you have 100 test. You'll for sure notice

1103, 2024

Testing behavior, not implementation details – part 1

When you want to learn about software testing, you quickly hear the famous "Test behavior, not implementation details". More often than not, it doesn't help you much. I know that - it was the same for me. So what does

1402, 2024

Factory Fixtures

Factory fixtures, what in the whole earth would that be? When you want to test your code thoroughly, you have to write quite a few tests. This way, you ensure that your code is working as expected. Nevertheless, you

702, 2024

Single assertion per test – rule or guideline?

Python Testing Tip #1 Why do we even test our software? If you've read anything about software testing, I'm sure you've stumbled across the idea of "one assertion per test". Sounds like a simple idea, right? Thinking about

Subscribe To Python Testing Tips

Get Python Testing Tips to Your Inbox

Subscribe To Python Testing Tips

Get Python Testing Tips to Your Inbox

Go to Top