How to Write Python Tests You Can Rely On | Issue #66


Hey there,

Writing software tests doesn't have to be hard.

In my latest video, I walk you through how to write unit tests in Python with pytest

Here’s what you’ll learn:

  • The basics of unit testing (and why they matter)
  • The difference between mocking and monkey patching, and when to use each
  • How to refactor code for better testability
  • How to use pytest fixtures to avoid repetition
  • Advanced pytest features like parametrize, raises, skip, and xfail

You’ll see multiple approaches in action, from simple stubs to full MagicMock clients, so you can choose the one that fits your workflow best.

Happy testing! :)

Arjan


Do you enjoy my content on YouTube and would you like to dive in deeper?

🚀 Check out my online courses

My courses have helped thousands of developers take the next step in their careers. Check out these courses to help grow your skills and become a senior developer:

🔧 Need help with a complex codebase?

If your team is struggling with tech debt, unclear architecture, or cloud costs that keep creeping up, my team and I can help. We don’t just review, we get in and fix things. We’re only working with a few companies at a time to stay focused, so if it sounds like a fit:

Unsubscribe | Send by ArjanCodes

Wolvenplein 25, Utrecht, UT 3512 CK

The Friday Loop

Every Friday, you'll get a recap of the most important and exciting Python and coding news. The Friday Loop also keeps everyone posted on new ArjanCodes courses and any limited offers coming up.

Read more from The Friday Loop

Hi there, When you start a new Python project, it often begins as a single file. Before you know it, that file turns into a tangle of routes, configs, and ad-hoc fixes. Scaling that into something a team can maintain is tough. In my latest video, I show you the anatomy of a scalable Python project. We’ll cover folder structure, config management, logging, testing, and how to set up pyproject.toml, .python-version, Docker, and docker-compose for smooth local and production environments. I’ll...

Hi there, You’ve probably heard of the SOLID principles... and maybe even felt guilty for not applying them more. But how useful are they really when you’re writing Python? In my latest video, I take a simple but realistic example and implement it three ways: A messy, all-in-one class that gets the job done A cleaner, class-based version that follows SOLID principles A lightweight, functional approach that may be more Pythonic In the end, the important thing is to understand where design...

Hi there, You’ve probably heard it before: "Singletons are an anti-pattern!" And… yes. They often are. Especially when they’re used to add global state to your app and create coupling and bugs. But... there’s a different side of the Singleton pattern. In this week’s video, I cover why Singletons get a bad reputation. I'll also show you a practical use case where Singleton might actually be helpful. Enjoy the video, and hope you have a great weekend. Cheers, Arjan Do you enjoy my content on...