Ads skipped

How to Write Great Unit Tests in Python

50K views · Aug 15, 2025 · Education

Comments · 63

  • @samsung40_media87 · 1 year ago

    I prefer mock vs monkey patching. Though they're not apples v apples, I like mock's different asserts

    15

  • @francescomarchisotti · 1 year ago

    In the video you talked about other kinds of testing and while on YouTube and on your channel I find a lot of videos about unit testing, I feel like these other kinds are always a bit neglected<br>Can you do a video or a series of videos going more in depth about this topic of testing in all its different aspects? I think it would provide great value and even maybe stand out in YouTube’s Python community!

    8

  • @Golgafrincham · 1 year ago

    I like to use pytest.Parameter for parametrization. It is a bit more strict on typing and also gives you an ID of your tests where you can describe the current tests. It also integrates good with for example VS Code.

    13

  • @marukrzysz1731 · 1 year ago

    Great, more videos about testing would be nice. I feel like it is not covered enough , even in pytest documentation. I`m using Pytest-mock package for mocking so don`t have to import unittest library :p

    8

  • @yehuda100 · 1 year ago (edited)

    very important topic and not a lot of videos about it.

    4

  • @_DRMR_ · 1 year ago

    One thing we have in our CI is Integration Tests, where things like Database access or messaging behavior (ie. RabbitMQ) can be tested without mocking this functionality.<br>It makes setting up the testing environment a little bit harder, but it helps to confirm edge cases in a more realistic scenario.

    7

  • @argyroustavros · 1 year ago

    you should also have mentioned autospec or create_autospec for mocking the real signature of thje object or function. Without it calling a method that doesn&apos;t exist would also raise.<br><br>In general I feel that you could go more in depth or production ready for your videos, there are a lot of python channels already that touch on the surface of topics and never go too deep.

    10

  • @chandanjha5022 · 1 month ago

    Great thought ❤❤❤❤❤

  • @ThijsFranck · 1 year ago (edited)

    Great stuff as usual, thanks Arjan!<br><br>I&apos;d be interested to hear your take on the other types of testing that you mentioned, such as end-to-end testing. I&apos;ve found these types of tests especially useful to validate code from a user perspective!<br><br>Some libraries I&apos;ve experimented with include testcontainers and playwright in combination with pytest.<br><br>Would love to hear your thoughts, keep up the amazing work!

    7

  • @thegimel · 1 year ago

    Thank you! Please follow up with videos on other types of testing 🙏

    1

  • @hansdietrich1496 · 1 year ago

    About mocking: Imho the best approach would have been, to separate the unreliable data retrieval from the net from the deterministic local data processing. Then you can test the local processing, e.g. of the weather json response separately, without having to mess around with monkey patching.<br><br>While monkey patching is surely powerfull, quite often it just shows inflexible or suboptimal design of the functions, which you want to test. It mainly makes sense for some higher level functions.

    1

  • @thebrigandier · 1 year ago

    Great info, looking forward to trying these out.

    1

Up next

LIVE

How To Write Unit Tests For Existing Python Code // Part 1 of 2

ArjanCodes · 233K views

LIVE

SQLAlchemy vs SQLModel: Which Should You Use?

ArjanCodes · 130K views

LIVE

Learning Python Feels Easy. Until It Isn’t.

ArjanCodes · 47K views

LIVE

Things (Almost) No One Thinks About When Designing Functions in Python

ArjanCodes · 110K views

LIVE

Reinforcement Learning from Scratch: Code a Q-Learning Agent in Python

QuietLoom AI Lab · 47 views

LIVE

Don’t Use Boolean Flags in Python, Use Policies Instead

ArjanCodes · 165K views

LIVE

Thoughts About Unit Testing | Prime Reacts

The PrimeTime · 350K views

LIVE

What Most Python Developers Miss About Generators

ArjanCodes · 30K views

LIVE

How to Test Python Code with PyTest (Best Practices & Examples)

Code with Josh · 11K views

LIVE

How to Write Python That Feels Like Python

ArjanCodes · 174K views

LIVE

Don't learn AI Agents without Learning these Fundamentals

KodeKloud · 1.2M views

LIVE

How To Write Unit Tests (The Right Way)

Cody Engel · 64K views

LIVE

The Builder Pattern in Python: Finally Explained!

ArjanCodes · 65K views

LIVE

10 Python Features You’re Not Using (But Really Should)

ArjanCodes · 76K views

LIVE

Please Learn How To Write Tests in Python… • Pytest Tutorial

Tech With Tim · 244K views

LIVE

From Spaghetti Code to Clean Python

ArjanCodes · 126K views

LIVE

Why You Should Think Twice Before Using Returns in Python

ArjanCodes · 96K views

LIVE

EU Tells USA To BACK OFF! Dutch BAN Microsoft, Bonds COLLAPSE, Trump PANICS

House of El · 236K views

LIVE

Software Testing Theory + A Few Less Obvious Testing Techniques

ArjanCodes · 49K views

LIVE

Mastering API Testing with FastAPI: Databases, Dependencies, and More!

ArjanCodes · 107K views

YouTube, with the door locked.

Aegis plays a clean stream instead of YouTube's player, so pre-roll ads, trackers, and fingerprinting never ride along. Drop Shields any time if you want the official player back.