Unit Testing
Learn to maintain a healthy codebase by creating unit tests using Python's built-in unittest framework!
StartKey Concepts
Review core concepts you need to learn to master this subject
SyntaxError
SyntaxError
age = 7 + 5 = 4
File "<stdin>", line 1
SyntaxError: can't assign to operator
A SyntaxError is reported by the Python interpreter when some portion of the code is incorrect. This can include misspelled keywords, missing or too many brackets or parenthesis, incorrect operators, missing or too many quotation marks, or other conditions.
Exceptions
Lesson 1 of 2
- 1It is truly an amazing feeling when our code works exactly the way we want it to. On the other hand, it can be equally frustrating when our code runs into errors. Since errors are such an integral …
- 2In the previous exercise (and probably many times before), we saw one type of exception called the NameError. The NameError is just one of the many built-in exceptions - exceptions that are built…
- 3Encountering exceptions isn’t always an accident. We can throw an exception at any time by using the raise keyword, even when Python would not normally throw it. We might want to raise an exceptio…
- 4So far, the exceptions we’ve encountered have caused our programs to stop executing. However, it is possible for programs to continue executing even after encountering an exception. This process is…
- 5The exception handlers from the previous exercise handled any exception hit during the try clause. However, in most cases, we will have an idea of the types of exceptions that might occur within ou…
- 6While handling a single exception is useful, Python also gives us the ability to handle multiple exceptions at once. We can list more than one exception type in a tuple with a single except clause….
- 7We’ve seen how exception handlers get executed when we encounter exceptions during a try clause - but what if we want to run some code only if we do not encounter an exception? Python provides us a…
- 8With try/except/else, we’ve seen how to run certain code when an exception occurs and other code when it does not. There is also a way to execute code regardless of whether an exception occurs - th…
- 9So far we have seen how to raise and manage built-in exceptions. In most programs, using built-in exceptions won’t always be the most detailed way to describe an error occurring. What if we could c…
- 10We’ve just seen how defining a simple exception class can provide a more specific and useful error to users. Defining a simple class is just the first step to creating better exceptions in our prog…
What you'll create
Portfolio projects that showcase your new skills
How you'll master it
Stress-test your knowledge with quizzes that help commit syntax to memory