<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/learn-python-testing-in-15-minutes-unittest-vs-pytest--lg95ubdat" -->

---
title: Learn Python Testing in 15 minutes (Unittest vs Pytest)
description: A practical comparison of Python's built-in unittest module and pytest, using a simple calculator class as the test subject. Covers the boilerplate-heavy...
canonical: https://daily.dev/posts/learn-python-testing-in-15-minutes-unittest-vs-pytest--lg95ubdat
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Learn Python Testing in 15 minutes (Unittest vs Pytest) | daily.dev
og:description: A practical comparison of Python's built-in unittest module and pytest, using a simple calculator class as the test subject. Covers the boilerplate-heavy...
og:url: https://daily.dev/posts/learn-python-testing-in-15-minutes-unittest-vs-pytest--lg95ubdat
og:image: https://api.daily.dev/og/posts/lG95ubDat.png
og:image:alt: Learn Python Testing in 15 minutes (Unittest vs Pytest)
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Learn Python Testing in 15 minutes (Unittest vs Pytest)

**[Indently](https://daily.dev/sources/indently)** · 15 min read · 1 upvotes · 0 comments

## Summary

A practical comparison of Python's built-in unittest module and pytest, using a simple calculator class as the test subject. Covers the boilerplate-heavy unittest approach (subclassing TestCase, setup methods, assert equal) versus pytest's cleaner style (plain functions, fixtures, plain assert statements). Demonstrates pytest's parametrize decorator for running multiple test cases with a single function, edge case testing with pytest.raises, and how pytest provides detailed failure output. Concludes with a side-by-side summary of both frameworks.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.youtube.com/watch?v=69ZNyVeJ6ik>

## Questions this post answers

### What are the main differences between pytest and unittest in Python?

Pytest uses plain functions instead of TestCase subclasses, plain assert statements instead of assertEqual, and opt-in fixtures instead of setUp methods. It also provides pytest.raises with a match argument for checking exception messages, and the parametrize decorator to run one test function across a table of inputs instead of writing duplicate test methods, as unittest requires.

_Developers weighing pytest against unittest can find comparisons like this one on daily.dev._

### How do you test that a function raises an exception with a specific error message in pytest?

Use the pytest.raises context manager with the expected exception type, and add the match argument set to a string or regex that the error message must match, for example pytest.raises(ValueError, match="cannot divide by zero"). This checks both that the exception type is raised and that its message matches the given text in one step.

_Anyone writing exception tests in Python can track patterns like this via daily.dev._

### How do you run multiple test cases with different inputs using one pytest function?

Use the pytest.mark.parametrize decorator, providing the names of the parameters as a string and a list of tuples where each tuple represents one test case's values. Pytest then runs the decorated test function once per tuple, labeling each run clearly in the output, so a single function can cover many input combinations, such as seven arithmetic cases in one test.

_Developers reducing test duplication with parametrize can keep up with such techniques on daily.dev._

## Similar posts on daily.dev

- [Testing Your Code With Python's unittest – Real Python](https://daily.dev/posts/testing-your-code-with-python-s-unittest-real-python-kb6n0cqus) · Real Python · 0 upvotes · 0 comments
- [Django's test runner is underrated](https://daily.dev/posts/django-s-test-runner-is-underrated-z3oosjhgz) · Planet Python · 1 upvotes · 0 comments
- [Improving Your Tests With the Python Mock Object Library – Real Python](https://daily.dev/posts/improving-your-tests-with-the-python-mock-object-library-real-python-elbphcay1) · Real Python · 0 upvotes · 0 comments
- [How to get more from Python integration testing](https://daily.dev/posts/how-to-get-more-from-python-integration-testing-obvsb128r) · Honeybadger · 0 upvotes · 0 comments
- [Test-Driven Development With pytest Quiz – Real Python](https://daily.dev/posts/test-driven-development-with-pytest-quiz-real-python-eqjpaowzy) · Real Python · 0 upvotes · 0 comments

---

Tags: [#python](https://daily.dev/tags/python), [#testing](https://daily.dev/tags/testing)

[View this post on daily.dev](https://daily.dev/posts/learn-python-testing-in-15-minutes-unittest-vs-pytest--lg95ubdat)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Learn Python Testing in 15 minutes (Unittest vs Pytest)","url":"https://daily.dev/posts/learn-python-testing-in-15-minutes-unittest-vs-pytest--lg95ubdat","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/learn-python-testing-in-15-minutes-unittest-vs-pytest--lg95ubdat"},"datePublished":"2026-07-23T16:22:41.905Z","dateModified":"2026-09-14T06:27:18.010Z","description":"A practical comparison of Python's built-in unittest module and pytest, using a simple calculator class as the test subject. Covers the boilerplate-heavy...","image":"https://i.ytimg.com/vi/69ZNyVeJ6ik/sddefault.jpg","thumbnailUrl":"https://i.ytimg.com/vi/69ZNyVeJ6ik/sddefault.jpg","isAccessibleForFree":true,"articleSection":"Indently","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Indently","logo":"https://media.daily.dev/image/upload/s--u6wAXJI9--/f_auto/v1725038127/logos/indently","url":"https://daily.dev/sources/indently"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/learn-python-testing-in-15-minutes-unittest-vs-pytest--lg95ubdat","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"python,testing","timeRequired":"PT15M","video":{"@type":"VideoObject","name":"Learn Python Testing in 15 minutes (Unittest vs Pytest)","description":"A practical comparison of Python's built-in unittest module and pytest, using a simple calculator class as the test subject. Covers the boilerplate-heavy...","thumbnailUrl":"https://i.ytimg.com/vi/69ZNyVeJ6ik/sddefault.jpg","uploadDate":"2026-07-23T16:22:41.905Z","duration":"PT15M","url":"https://api.daily.dev/r/lG95ubDat","embedUrl":"https://www.youtube.com/embed/69ZNyVeJ6ik"}}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Indently","item":"https://daily.dev/sources/indently"},{"@type":"ListItem","position":3,"name":"Learn Python Testing in 15 minutes (Unittest vs Pytest)"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/learn-python-testing-in-15-minutes-unittest-vs-pytest--lg95ubdat#faq","mainEntity":[{"@type":"Question","name":"What are the main differences between pytest and unittest in Python?","acceptedAnswer":{"@type":"Answer","text":"Pytest uses plain functions instead of TestCase subclasses, plain assert statements instead of assertEqual, and opt-in fixtures instead of setUp methods. It also provides pytest.raises with a match argument for checking exception messages, and the parametrize decorator to run one test function across a table of inputs instead of writing duplicate test methods, as unittest requires. Developers weighing pytest against unittest can find comparisons like this one on daily.dev."}},{"@type":"Question","name":"How do you test that a function raises an exception with a specific error message in pytest?","acceptedAnswer":{"@type":"Answer","text":"Use the pytest.raises context manager with the expected exception type, and add the match argument set to a string or regex that the error message must match, for example pytest.raises(ValueError, match=\"cannot divide by zero\"). This checks both that the exception type is raised and that its message matches the given text in one step. Anyone writing exception tests in Python can track patterns like this via daily.dev."}},{"@type":"Question","name":"How do you run multiple test cases with different inputs using one pytest function?","acceptedAnswer":{"@type":"Answer","text":"Use the pytest.mark.parametrize decorator, providing the names of the parameters as a string and a list of tuples where each tuple represents one test case's values. Pytest then runs the decorated test function once per tuple, labeling each run clearly in the output, so a single function can cover many input combinations, such as seven arithmetic cases in one test. Developers reducing test duplication with parametrize can keep up with such techniques on daily.dev."}}]}
```

