From the course: Unit Testing in Python
Unlock the full course today
Join today to access over 24,900 courses taught by industry experts.
Solution: Exceptions - Python Tutorial
From the course: Unit Testing in Python
Solution: Exceptions
(upbeat music) - [Instructor] Here's one manner of completing this challenge. We can begin by adding an invalid point whose name will be five instead of a standard string. You can see this on line 16. Since we want to create an isolated test that only checks the validity of the city name argument, let's give a valid latitude and longitude coordinate. When you run pytest, you should see an error at this point because we don't have a matching source code function to trigger this error. When moving to update it, you could have done so as follows: expanding the window with our source code, we can see the following: we can check if the name is a string instance during the initialization of the point and its init method. You can opt to either use is instance or type methods to make this validation. In my case, I chose to use is instance. If this function returns false, we want to raise a value error. Additionally, if we don't trigger a value error, we can move on to assigning our name…