René's URL Explorer Experiment


Title: Python's unittest: Writing Unit Tests for Your Code – Real Python

Open Graph Title: Python's unittest: Writing Unit Tests for Your Code – Real Python

Description: In this tutorial, you'll learn how to use the unittest framework to create unit tests for your Python code. Along the way, you'll also learn how to create test cases, fixtures, test suites, and more.

Open Graph Description: In this tutorial, you'll learn how to use the unittest framework to create unit tests for your Python code. Along the way, you'll also learn how to create test cases, fixtures, test suites, and more.

Mail addresses
?subject=Python article for you&body=Python's unittest: Writing Unit Tests for Your Code on Real Python https://realpython.com/python-unittest/

Opengraph URL: https://realpython.com/python-unittest/

X: @realpython

direct link

Domain: realpython.com


Hey, it has json ld scripts:
{
  "@context": "http://schema.org",
  "@type": "Article",
  "headline": "Python's unittest: Writing Unit Tests for Your Code",
  "image": {
    "@type": "ImageObject",
    "url": "https://files.realpython.com/media/Python-unittest_Watermarked.f6549bba7422.jpg",
    "width": 1920,
    "height": 1080
  },
  "mainEntityOfPage": {
    "@type": "WebPage",
    "@id": "https://realpython.com/python-unittest/",
    "lastReviewed": "2024-05-08",
    "author": {
      "@type": "Person",
      "name": "Leodanis Pozo Ramos",
      "image": "https://realpython.com/cdn-cgi/image/width=862,height=862,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/Perfil_final1.9f896bc212f6.jpg",
      "url": "https://realpython.com/team/lpozoramos/",
      "affiliation": {
        "@type": "Organization",
        "@id": "https://realpython.com/#organization",
        "name": "Real Python",
        "url": "https://realpython.com",
        "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
      }
    },
    "reviewedBy": [
      {
        "@type": "Person",
        "name": "Aldren Santos",
        "image": "https://realpython.com/cdn-cgi/image/width=500,height=500,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/Aldren_Santos_Real_Python.6b0861d8b841.png",
        "url": "https://realpython.com/team/asantos/",
        "affiliation": {
          "@type": "Organization",
          "@id": "https://realpython.com/#organization",
          "name": "Real Python",
          "url": "https://realpython.com",
          "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
        }
      },
      {
        "@type": "Person",
        "name": "Brenda Weleschuk",
        "image": "https://realpython.com/cdn-cgi/image/width=320,height=320,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/IMG_3324_1.50b309355fc1.jpg",
        "url": "https://realpython.com/team/bweleschuk/",
        "affiliation": {
          "@type": "Organization",
          "@id": "https://realpython.com/#organization",
          "name": "Real Python",
          "url": "https://realpython.com",
          "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
        }
      },
      {
        "@type": "Person",
        "name": "Geir Arne Hjelle",
        "image": "https://realpython.com/cdn-cgi/image/width=800,height=800,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/gahjelle.470149ee709e.jpg",
        "url": "https://realpython.com/team/gahjelle/",
        "affiliation": {
          "@type": "Organization",
          "@id": "https://realpython.com/#organization",
          "name": "Real Python",
          "url": "https://realpython.com",
          "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
        }
      },
      {
        "@type": "Person",
        "name": "Martin Breuss",
        "image": "https://realpython.com/cdn-cgi/image/width=456,height=456,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/martin_breuss_python_square.efb2b07faf9f.jpg",
        "url": "https://realpython.com/team/mbreuss/",
        "affiliation": {
          "@type": "Organization",
          "@id": "https://realpython.com/#organization",
          "name": "Real Python",
          "url": "https://realpython.com",
          "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
        }
      }
    ]
  },
  "datePublished": "2024-04-29T14:00:00+00:00",
  "dateModified": "2024-05-08T11:58:06.205828+00:00",
  "publisher": {
    "@type": "Organization",
    "@id": "https://realpython.com/#organization",
    "name": "Real Python",
    "url": "https://realpython.com",
    "logo": {
      "@type": "ImageObject",
      "url": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png",
      "width": 512,
      "height": 512
    },
    "description": "Real Python is a leading provider of online Python education and one of the largest language-specific online communities for software developers. It publishes high-quality learning resources, such as tutorials, books, and courses to an audience of millions of developers, data scientists, and machine learning engineers each month.",
    "slogan": "Become a Python Expert",
    "email": "info@realpython.com",
    "sameAs": [
      "https://github.com/realpython",
      "https://www.youtube.com/realpython",
      "https://twitter.com/realpython",
      "https://x.com/realpython",
      "https://www.linkedin.com/company/realpython-com/",
      "https://www.facebook.com/learnrealpython",
      "https://www.instagram.com/realpython",
      "https://www.tiktok.com/@realpython.com"
    ]
  },
  "author": {
    "@type": "Person",
    "name": "Leodanis Pozo Ramos",
    "image": "https://realpython.com/cdn-cgi/image/width=862,height=862,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/Perfil_final1.9f896bc212f6.jpg",
    "url": "https://realpython.com/team/lpozoramos/",
    "affiliation": {
      "@type": "Organization",
      "@id": "https://realpython.com/#organization",
      "name": "Real Python",
      "url": "https://realpython.com",
      "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
    }
  },
  "description": "In this tutorial, you'll learn how to use the unittest framework to create unit tests for your Python code. Along the way, you'll also learn how to create test cases, fixtures, test suites, and more."
}

authorReal Python
twitter:cardsummary_large_image
twitter:imagehttps://files.realpython.com/media/Python-unittest_Watermarked.f6549bba7422.jpg
og:imagehttps://files.realpython.com/media/Python-unittest_Watermarked.f6549bba7422.jpg
twitter:creator@realpython
og:typearticle

Links:

https://realpython.com/
Start Herehttps://realpython.com/start-here/
Learn Python https://realpython.com/python-unittest/
Python Tutorials →In-depth articles and video courseshttps://realpython.com/search?kind=article&kind=course&order=newest
Learning Paths →Guided study plans for accelerated learninghttps://realpython.com/learning-paths/
Quizzes & Exercises →Check your learning progresshttps://realpython.com/quizzes/
Browse Topics →Focus on a specific area or skill levelhttps://realpython.com/tutorials/all/
Community Chat →Learn with other Pythonistashttps://realpython.com/community/
Office Hours →Live Q&A calls with Python expertshttps://realpython.com/office-hours/
Podcast →Hear what’s new in the world of Pythonhttps://realpython.com/podcasts/rpp/
Books →Round out your knowledge and learn offlinehttps://realpython.com/products/books/
Reference →Concise definitions for common Python termshttps://realpython.com/ref/
Code Mentor →BetaPersonalized code assistance & learning toolshttps://realpython.com/mentor/
Unlock All Content →https://realpython.com/account/join/
More https://realpython.com/python-unittest/
Learner Storieshttps://realpython.com/learner-stories/
Python Newsletterhttps://realpython.com/newsletter/
Python Job Boardhttps://www.pythonjobshq.com
Meet the Teamhttps://realpython.com/team/
Become a Tutorial Writerhttps://realpython.com/write-for-us/
Become a Video Instructorhttps://realpython.com/become-an-instructor/
Searchhttps://realpython.com/search
https://realpython.com/search
Joinhttps://realpython.com/account/join/
Sign‑Inhttps://realpython.com/account/login/?next=%2Fpython-unittest%2F
Browse Topicshttps://realpython.com/tutorials/all/
Guided Learning Pathshttps://realpython.com/learning-paths/
Basicshttps://realpython.com/search?level=basics
Intermediatehttps://realpython.com/search?level=intermediate
Advancedhttps://realpython.com/search?level=advanced
aihttps://realpython.com/tutorials/ai/
algorithmshttps://realpython.com/tutorials/algorithms/
apihttps://realpython.com/tutorials/api/
best-practiceshttps://realpython.com/tutorials/best-practices/
careerhttps://realpython.com/tutorials/career/
communityhttps://realpython.com/tutorials/community/
databaseshttps://realpython.com/tutorials/databases/
data-sciencehttps://realpython.com/tutorials/data-science/
data-structureshttps://realpython.com/tutorials/data-structures/
data-vizhttps://realpython.com/tutorials/data-viz/
devopshttps://realpython.com/tutorials/devops/
djangohttps://realpython.com/tutorials/django/
dockerhttps://realpython.com/tutorials/docker/
editorshttps://realpython.com/tutorials/editors/
flaskhttps://realpython.com/tutorials/flask/
front-endhttps://realpython.com/tutorials/front-end/
gamedevhttps://realpython.com/tutorials/gamedev/
guihttps://realpython.com/tutorials/gui/
machine-learninghttps://realpython.com/tutorials/machine-learning/
newshttps://realpython.com/tutorials/news/
numpyhttps://realpython.com/tutorials/numpy/
projectshttps://realpython.com/tutorials/projects/
pythonhttps://realpython.com/tutorials/python/
stdlibhttps://realpython.com/tutorials/stdlib/
testinghttps://realpython.com/tutorials/testing/
toolshttps://realpython.com/tutorials/tools/
web-devhttps://realpython.com/tutorials/web-dev/
web-scrapinghttps://realpython.com/tutorials/web-scraping/
Table of Contentshttps://realpython.com/python-unittest/#toc
Testing Your Python Codehttps://realpython.com/python-unittest/#testing-your-python-code
Getting to Know Python’s unittesthttps://realpython.com/python-unittest/#getting-to-know-pythons-unittest
Organizing Your Tests With the TestCase Classhttps://realpython.com/python-unittest/#organizing-your-tests-with-the-testcase-class
Creating Test Caseshttps://realpython.com/python-unittest/#creating-test-cases
Running unittest Testshttps://realpython.com/python-unittest/#running-unittest-tests
Skipping Testshttps://realpython.com/python-unittest/#skipping-tests
Creating Subtestshttps://realpython.com/python-unittest/#creating-subtests
Exploring the Available Assert Methodshttps://realpython.com/python-unittest/#exploring-the-available-assert-methods
Comparing Valueshttps://realpython.com/python-unittest/#comparing-values
Comparing Objects by Their Identityhttps://realpython.com/python-unittest/#comparing-objects-by-their-identity
Comparing Collectionshttps://realpython.com/python-unittest/#comparing-collections
Running Membership Testshttps://realpython.com/python-unittest/#running-membership-tests
Checking for an Object’s Typehttps://realpython.com/python-unittest/#checking-for-an-objects-type
Testing for Exceptionshttps://realpython.com/python-unittest/#testing-for-exceptions
Using Custom Assert Methodshttps://realpython.com/python-unittest/#using-custom-assert-methods
Using unittest From the Command Linehttps://realpython.com/python-unittest/#using-unittest-from-the-command-line
Running Testshttps://realpython.com/python-unittest/#running-tests
Discovering Tests Automaticallyhttps://realpython.com/python-unittest/#discovering-tests-automatically
Using Command-Line Optionshttps://realpython.com/python-unittest/#using-command-line-options
Grouping Your Tests With the TestSuite Classhttps://realpython.com/python-unittest/#grouping-your-tests-with-the-testsuite-class
Creating Test Suites With the TestSuite() Constructorhttps://realpython.com/python-unittest/#creating-test-suites-with-the-testsuite-constructor
Adding Tests to a Suite: .addTest() and .addTests()https://realpython.com/python-unittest/#adding-tests-to-a-suite-addtest-and-addtests
Creating Suites With the load_tests() Functionhttps://realpython.com/python-unittest/#creating-suites-with-the-load_tests-function
Creating Test Fixtureshttps://realpython.com/python-unittest/#creating-test-fixtures
Test Fixtureshttps://realpython.com/python-unittest/#test-fixtures
Class-Level Fixtureshttps://realpython.com/python-unittest/#class-level-fixtures
Module-Level Fixtureshttps://realpython.com/python-unittest/#module-level-fixtures
Debugging Failing Testshttps://realpython.com/python-unittest/#debugging-failing-tests
A Quick Example: FizzBuzzhttps://realpython.com/python-unittest/#a-quick-example-fizzbuzz
A Test-Driven Example: Rock, Paper, and Scissorshttps://realpython.com/python-unittest/#a-test-driven-example-rock-paper-and-scissors
Testing With Fake Objects: unittest.mockhttps://realpython.com/python-unittest/#testing-with-fake-objects-unittestmock
Conclusionhttps://realpython.com/python-unittest/#conclusion
https://realpython.com/feedback/survey/article/python-unittest/liked/?from=article-sidebar
https://realpython.com/feedback/survey/article/python-unittest/disliked/?from=article-sidebar
Leodanis Pozo Ramoshttps://realpython.com/python-unittest/#author
https://realpython.com/python-unittest/#reader-comments
intermediatehttps://realpython.com/tutorials/intermediate/
stdlibhttps://realpython.com/tutorials/stdlib/
testinghttps://realpython.com/tutorials/testing/
Testing Your Python Codehttps://realpython.com/python-unittest/#testing-your-python-code
Getting to Know Python’s unittesthttps://realpython.com/python-unittest/#getting-to-know-pythons-unittest
Organizing Your Tests With the TestCase Classhttps://realpython.com/python-unittest/#organizing-your-tests-with-the-testcase-class
Creating Test Caseshttps://realpython.com/python-unittest/#creating-test-cases
Running unittest Testshttps://realpython.com/python-unittest/#running-unittest-tests
Skipping Testshttps://realpython.com/python-unittest/#skipping-tests
Creating Subtestshttps://realpython.com/python-unittest/#creating-subtests
Exploring the Available Assert Methodshttps://realpython.com/python-unittest/#exploring-the-available-assert-methods
Comparing Valueshttps://realpython.com/python-unittest/#comparing-values
Comparing Objects by Their Identityhttps://realpython.com/python-unittest/#comparing-objects-by-their-identity
Comparing Collectionshttps://realpython.com/python-unittest/#comparing-collections
Running Membership Testshttps://realpython.com/python-unittest/#running-membership-tests
Checking for an Object’s Typehttps://realpython.com/python-unittest/#checking-for-an-objects-type
Testing for Exceptionshttps://realpython.com/python-unittest/#testing-for-exceptions
Using Custom Assert Methodshttps://realpython.com/python-unittest/#using-custom-assert-methods
Using unittest From the Command Linehttps://realpython.com/python-unittest/#using-unittest-from-the-command-line
Running Testshttps://realpython.com/python-unittest/#running-tests
Discovering Tests Automaticallyhttps://realpython.com/python-unittest/#discovering-tests-automatically
Using Command-Line Optionshttps://realpython.com/python-unittest/#using-command-line-options
Grouping Your Tests With the TestSuite Classhttps://realpython.com/python-unittest/#grouping-your-tests-with-the-testsuite-class
Creating Test Suites With the TestSuite() Constructorhttps://realpython.com/python-unittest/#creating-test-suites-with-the-testsuite-constructor
Adding Tests to a Suite: .addTest() and .addTests()https://realpython.com/python-unittest/#adding-tests-to-a-suite-addtest-and-addtests
Creating Suites With the load_tests() Functionhttps://realpython.com/python-unittest/#creating-suites-with-the-load_tests-function
Creating Test Fixtureshttps://realpython.com/python-unittest/#creating-test-fixtures
Test Fixtureshttps://realpython.com/python-unittest/#test-fixtures
Class-Level Fixtureshttps://realpython.com/python-unittest/#class-level-fixtures
Module-Level Fixtureshttps://realpython.com/python-unittest/#module-level-fixtures
Debugging Failing Testshttps://realpython.com/python-unittest/#debugging-failing-tests
A Quick Example: FizzBuzzhttps://realpython.com/python-unittest/#a-quick-example-fizzbuzz
A Test-Driven Example: Rock, Paper, and Scissorshttps://realpython.com/python-unittest/#a-test-driven-example-rock-paper-and-scissors
Testing With Fake Objects: unittest.mockhttps://realpython.com/python-unittest/#testing-with-fake-objects-unittestmock
Conclusionhttps://realpython.com/python-unittest/#conclusion
Remove adshttps://realpython.com/account/join/
standard libraryhttps://docs.python.org/3/library/index.html
object-oriented programminghttps://realpython.com/python3-object-oriented-programming/
inheritancehttps://realpython.com/inheritance-composition-python/
assertionshttps://realpython.com/python-assert-statement/
testinghttps://realpython.com/python-testing/
Click here to download the free sample codehttps://realpython.com/bonus/python-unittest-code/
https://realpython.com/quizzes/python-unittest/
Python's unittest: Writing Unit Tests for Your Codehttps://realpython.com/quizzes/python-unittest/
https://realpython.com/python-unittest/#testing-your-python-code
software testinghttps://en.wikipedia.org/wiki/Software_testing
unit testinghttps://en.wikipedia.org/wiki/Unit_testing
Functionshttps://realpython.com/defining-your-own-python-function/
methodshttps://realpython.com/python-classes/#providing-behavior-with-methods
callableshttps://realpython.com/python-callable-instances/
standard libraryhttps://docs.python.org/3/library/index.html
testing frameworkhttps://en.wikipedia.org/wiki/Test_automation#Framework_approach_in_automation
test automationhttps://en.wikipedia.org/wiki/Test_automation
docstringshttps://realpython.com/how-to-write-docstrings-in-python/
Python’s doctest: Document and Test Your Code at Oncehttps://realpython.com/python-doctest/
packagehttps://realpython.com/python-modules-packages/#python-packages
unittesthttps://docs.python.org/3/library/unittest.html#module-unittest
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-unittest/#getting-to-know-pythons-unittest
JUnithttps://en.wikipedia.org/wiki/JUnit
Javahttps://realpython.com/java-vs-python/
object-orientedhttps://realpython.com/python3-object-oriented-programming/
https://realpython.com/python-unittest/#organizing-your-tests-with-the-testcase-class
abs()https://realpython.com/python-absolute-value/
https://realpython.com/python-unittest/#creating-test-cases
test discoveryhttps://docs.python.org/3/library/unittest.html#test-discovery
assertionshttps://realpython.com/python-assert-statement/#what-are-assertions
Exploring the Available Assert Methodshttps://realpython.com/python-unittest/#exploring-the-available-assert-methods
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-unittest/#running-unittest-tests
main()https://docs.python.org/3/library/unittest.html#unittest.main
runhttps://realpython.com/run-python-scripts/
Using unittest From the Command Linehttps://realpython.com/python-unittest/#using-unittest-from-the-command-line
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-unittest/#skipping-tests
@unittest.skip(reason)https://docs.python.org/3/library/unittest.html#unittest.skip
@unittest.skipIf(condition, reason)https://docs.python.org/3/library/unittest.html#unittest.skipIf
@unittest.skipUnless(condition, reason)https://docs.python.org/3/library/unittest.html#unittest.skipUnless
3.12https://realpython.com/python312-new-features/
Windowshttps://realpython.com/python-unittest/#windows-1
Linux + macOShttps://realpython.com/python-unittest/#linux-macos-1
3.11https://realpython.com/python311-exception-groups/
https://realpython.com/python-unittest/#creating-subtests
subTest()https://docs.python.org/3/library/unittest.html#unittest.TestCase.subTest
modulo operatorhttps://realpython.com/python-modulo-operator/
Booleanhttps://realpython.com/python-boolean/
with statementhttps://realpython.com/python-with-statement/
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-unittest/#exploring-the-available-assert-methods
https://realpython.com/python-unittest/#comparing-values
.assertEqual(a, b)https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertEqual
.assertNotEqual(a, b)https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertNotEqual
.assertTrue(x)https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertTrue
.assertFalse(x)https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertFalse
Boolean-valuedhttps://en.wikipedia.org/wiki/Boolean-valued_function
https://realpython.com/python-unittest/#comparing-objects-by-their-identity
identityhttps://realpython.com/python-mutable-vs-immutable-types/#objects-value-identity-and-type
CPython implementationhttps://realpython.com/cpython-source-code-guide/
ishttps://realpython.com/python-is-identity-vs-equality/
is nothttps://realpython.com/python-is-identity-vs-equality/
.assertIs(a, b)https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertIs
.assertIsNot(a, b)https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertIsNot
.assertIsNone(x)https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertIsNone
.assertIsNotNone(x)https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertIsNotNone
null valuehttps://realpython.com/null-in-python/
cachedhttps://realpython.com/lru-cache-python/
singletonhttps://realpython.com/primer-on-python-decorators/#creating-singletons
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-unittest/#comparing-collections
listshttps://realpython.com/python-list/
tupleshttps://realpython.com/python-tuple/
stringshttps://realpython.com/python-strings/
dictionarieshttps://realpython.com/python-dicts/
setshttps://realpython.com/python-sets/
.assertSequenceEqual(a, b)https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertSequenceEqual
.assertMultiLineEqual(a, b)https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertMultiLineEqual
.assertListEqual(a, b)https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertListEqual
.assertTupleEqual(a, b)https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertTupleEqual
.assertDictEqual(a, b)https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertDictEqual
.assertSetEqual(a, b)https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertSetEqual
https://realpython.com/python-unittest/#running-membership-tests
inhttps://realpython.com/python-in-operator/#pythons-in-operator
not inhttps://realpython.com/python-in-operator/#pythons-not-in-operator
.assertIn(a, b)https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertIn
.assertNotIn(a, b)https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertNotIn
https://realpython.com/python-unittest/#checking-for-an-objects-type
.assertIsInstance(a, b)https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertIsInstance
.assertNotIsInstance(a, b)https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertNotIsInstance
isinstance()https://realpython.com/what-does-isinstance-do-in-python/
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-unittest/#testing-for-exceptions
raisehttps://realpython.com/python-raise-exception/
.assertRaises(exc, fun, *args, **kwds)https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertRaises
.assertRaisesRegex(exc, r, fun, *args, **kwds)https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertRaisesRegex
regular expressionshttps://realpython.com/regex-python/
conditionalhttps://realpython.com/python-conditional-statements/
warningshttps://realpython.com/python-built-in-exceptions/#getting-to-know-warnings
.assertWarns(warn, fun, *args, **kwds)https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertWarns
.assertWarnsRegex(warn, r, fun, *args, **kwds)https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertWarnsRegex
.assertLogs(logger, level)https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertLogs
.assertNoLogs(logger, level)https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertNoLogs
categoryhttps://docs.python.org/3/library/warnings.html#warning-categories
DeprecationWarninghttps://docs.python.org/3/library/exceptions.html#DeprecationWarning
logginghttps://realpython.com/python-logging-source-code/
https://realpython.com/python-unittest/#using-custom-assert-methods
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-unittest/#using-unittest-from-the-command-line
command-line interface (CLI)https://realpython.com/command-line-interfaces-python-argparse/
https://realpython.com/python-unittest/#running-tests
import pathhttps://docs.python.org/3/glossary.html#term-import-path
https://realpython.com/python-unittest/#discovering-tests-automatically
test suitehttps://realpython.com/python-unittest/#grouping-your-tests-with-the-testsuite-class
subcommandhttps://realpython.com/command-line-interfaces-python-argparse/#commands-arguments-options-parameters-and-subcommands
glob patternshttps://en.wikipedia.org/wiki/Glob_(programming)
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-unittest/#using-command-line-options
command-line optionshttps://docs.python.org/3/library/unittest.html#command-line-options
https://realpython.com/python-unittest/#grouping-your-tests-with-the-testsuite-class
https://realpython.com/python-unittest/#creating-test-suites-with-the-testsuite-constructor
constructorhttps://realpython.com/python-class-constructor/
TextTestRunnerhttps://docs.python.org/3/library/unittest.html#unittest.TextTestRunner
https://realpython.com/python-unittest/#adding-tests-to-a-suite-addtest-and-addtests
.addTest()https://docs.python.org/3/library/unittest.html#unittest.TestSuite.addTest
.addTests()https://docs.python.org/3/library/unittest.html#unittest.TestSuite.addTests
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-unittest/#creating-suites-with-the-load_tests-function
load_tests()https://docs.python.org/3/library/unittest.html#load-tests-protocol
TestLoaderhttps://docs.python.org/3/library/unittest.html#unittest.TestLoader
.loadTestsFromTestCase()https://docs.python.org/3/library/unittest.html#unittest.TestLoader.loadTestsFromTestCase
https://realpython.com/python-unittest/#creating-test-fixtures
fileshttps://realpython.com/working-with-files-in-python/
dataframeshttps://realpython.com/pandas-dataframe/
.setUp()https://docs.python.org/3/library/unittest.html#unittest.TestCase.setUp
.tearDown()https://docs.python.org/3/library/unittest.html#unittest.TestCase.tearDown
.setUpClass()https://docs.python.org/3/library/unittest.html#unittest.TestCase.setUpClass
.tearDownClass()https://docs.python.org/3/library/unittest.html#unittest.TestCase.tearDownClass
@classmethodhttps://realpython.com/python-classes/#class-methods-with-classmethod
setUpModule()https://docs.python.org/3/library/unittest.html#setupmodule-and-teardownmodule
tearDownModule()https://docs.python.org/3/library/unittest.html#setupmodule-and-teardownmodule
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-unittest/#test-fixtures
stackhttps://realpython.com/how-to-implement-python-stack/
special methodshttps://realpython.com/python-magic-methods/
len()https://realpython.com/len-python-function/
for loopshttps://realpython.com/python-for-loop/
reversed()https://realpython.com/python-reverse-list/
https://realpython.com/python-unittest/#class-level-fixtures
.__slots__https://realpython.com/python-classes/#lightweight-classes-with-__slots__
CSVhttps://realpython.com/python-interview-problem-parsing-csv-files/
csvhttps://docs.python.org/3/library/csv.html#module-csv
NamedTemporaryFilehttps://docs.python.org/3/library/tempfile.html#tempfile.NamedTemporaryFile
tempfilehttps://docs.python.org/3/library/tempfile.html#module-tempfile
constanthttps://realpython.com/python-constants/
https://realpython.com/python-unittest/#module-level-fixtures
SkipTesthttps://docs.python.org/3/library/unittest.html#unittest.SkipTest
https://realpython.com/python-unittest/#debugging-failing-tests
https://realpython.com/python-unittest/#a-quick-example-fizzbuzz
FizzBuzzhttps://en.wikipedia.org/wiki/Fizz_buzz#Programming
https://realpython.com/python-unittest/#a-test-driven-example-rock-paper-and-scissors
test-driven development (TDD)https://realpython.com/courses/test-driven-development-pytest/
https://realpython.com/python-unittest/#testing-with-fake-objects-unittestmock
unittest.mockhttps://realpython.com/python-mock-library/
Mockhttps://docs.python.org/3/library/unittest.mock.html#unittest.mock.Mock
MagicMockhttps://docs.python.org/3/library/unittest.mock.html#unittest.mock.MagicMock
magic methodshttps://realpython.com/python-magic-methods/
@patchhttps://docs.python.org/3/library/unittest.mock.html#unittest.mock.patch
datetimehttps://realpython.com/python-datetime/
https://realpython.com/python-unittest/#conclusion
Click here to download the free sample codehttps://realpython.com/bonus/python-unittest-code/
https://realpython.com/quizzes/python-unittest/
Python's unittest: Writing Unit Tests for Your Codehttps://realpython.com/quizzes/python-unittest/
https://realpython.com/feedback/survey/article/python-unittest/liked/?from=article-footer
https://realpython.com/feedback/survey/article/python-unittest/disliked/?from=article-footer
https://realpython.com/team/lpozoramos/
» More about Leodanishttps://realpython.com/team/lpozoramos/
https://realpython.com/team/asantos/
Aldrenhttps://realpython.com/team/asantos/
https://realpython.com/team/bweleschuk/
Brendahttps://realpython.com/team/bweleschuk/
https://realpython.com/team/gahjelle/
Geir Arnehttps://realpython.com/team/gahjelle/
https://realpython.com/team/mbreuss/
Martinhttps://realpython.com/team/mbreuss/
Level Up Your Python Skills »https://realpython.com/account/join/?utm_source=rp_article_footer&utm_content=python-unittest
Level Up Your Python Skills »https://realpython.com/account/join/?utm_source=rp_article_footer&utm_content=python-unittest
https://realpython.com/feedback/survey/article/python-unittest/liked/?from=article-comments
https://realpython.com/feedback/survey/article/python-unittest/disliked/?from=article-comments
LinkedInhttps://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Frealpython.com%2Fpython-unittest%2F
Twitterhttps://twitter.com/intent/tweet/?text=Interesting%20Python%20article%20on%20%40realpython%3A%20Python%27s%20unittest%3A%20Writing%20Unit%20Tests%20for%20Your%20Code&url=https%3A%2F%2Frealpython.com%2Fpython-unittest%2F
Blueskyhttps://bsky.app/intent/compose?text=Interesting%20Python%20article%20on%20%40realpython.com%3A%20Python%27s%20unittest%3A%20Writing%20Unit%20Tests%20for%20Your%20Code%20https%3A%2F%2Frealpython.com%2Fpython-unittest%2F
Facebookhttps://facebook.com/sharer/sharer.php?u=https%3A%2F%2Frealpython.com%2Fpython-unittest%2F
Get tips for asking good questionshttps://realpython.com/python-beginner-tips/#tip-9-ask-good-questions
get answers to common questions in our support portalhttps://support.realpython.com
Real Python Community Chathttps://realpython.com/community/
“Office Hours” Live Q&A Sessionhttps://realpython.com/office-hours/
intermediatehttps://realpython.com/tutorials/intermediate/
stdlibhttps://realpython.com/tutorials/stdlib/
testinghttps://realpython.com/tutorials/testing/
Understanding the Python Mock Object Libraryhttps://realpython.com/python-mock-library/?utm_source=realpython&utm_medium=web&utm_campaign=related-post&utm_content=python-unittest
Effective Python Testing With pytesthttps://realpython.com/pytest-python-testing/?utm_source=realpython&utm_medium=web&utm_campaign=related-post&utm_content=python-unittest
Getting Started With Testing in Pythonhttps://realpython.com/python-testing/?utm_source=realpython&utm_medium=web&utm_campaign=related-post&utm_content=python-unittest
How to Manage Python Projects With pyproject.tomlhttps://realpython.com/python-pyproject-toml/?utm_source=realpython&utm_medium=web&utm_campaign=related-post&utm_content=python-unittest
Logging in Pythonhttps://realpython.com/python-logging/?utm_source=realpython&utm_medium=web&utm_campaign=related-post&utm_content=python-unittest
https://realpython.com/account/signup/?intent=continue_reading&utm_source=rp&utm_medium=web&utm_campaign=rwn&utm_content=v1&next=%2Fpython-unittest%2F
Continue »https://realpython.com/account/signup/?intent=continue_reading&utm_source=rp&utm_medium=web&utm_campaign=rwn&utm_content=v1&next=%2Fpython-unittest%2F
Sign-Inhttps://realpython.com/account/login/?next=/python-unittest/
Start Herehttps://realpython.com/start-here/
Learning Resourceshttps://realpython.com/search
Code Mentorhttps://realpython.com/mentor/
Python Referencehttps://realpython.com/ref/
Python Cheat Sheethttps://realpython.com/cheatsheets/python/
Support Centerhttps://support.realpython.com/
Learning Pathshttps://realpython.com/learning-paths/
Quizzes & Exerciseshttps://realpython.com/quizzes/
Browse Topicshttps://realpython.com/tutorials/all/
Live Courseshttps://realpython.com/live/
Bookshttps://realpython.com/books/
Podcasthttps://realpython.com/podcasts/rpp/
Newsletterhttps://realpython.com/newsletter/
Community Chathttps://realpython.com/community/
Office Hourshttps://realpython.com/office-hours/
Learner Storieshttps://realpython.com/learner-stories/
Plans & Pricinghttps://realpython.com/account/join/
Team Planshttps://realpython.com/account/join-team/
For Businesshttps://realpython.com/account/join-team/inquiry/
For Schoolshttps://realpython.com/account/join-team/education-inquiry/
Reviewshttps://realpython.com/learner-stories/
About Ushttps://realpython.com/about/
Teamhttps://realpython.com/team/
Mission & Valueshttps://realpython.com/mission/
Editorial Guidelineshttps://realpython.com/editorial-guidelines/
Sponsorshipshttps://realpython.com/sponsorships/
Careershttps://realpython.workable.com
Press Kithttps://realpython.com/media-kit/
Merchhttps://realpython.com/merch
https://www.youtube.com/realpython
https://x.com/realpython
https://www.linkedin.com/company/realpython-com
https://www.facebook.com/LearnRealPython
https://github.com/realpython/
Privacy Policyhttps://realpython.com/privacy-policy/
Terms of Usehttps://realpython.com/terms/
Securityhttps://realpython.com/security/
Contacthttps://realpython.com/contact/
https://realpython.com/

Viewport: width=device-width, initial-scale=1, shrink-to-fit=no, viewport-fit=cover

Robots: max-image-preview:large


URLs of crawlers that visited me.