From the course: Unit Testing in Python
Unlock the full course today
Join today to access over 24,900 courses taught by industry experts.
Challenge: Exceptions - Python Tutorial
From the course: Unit Testing in Python
Challenge: Exceptions
(upbeat music) - [Instructor] Now that we can raise an exception for improper latitude and longitude coordinates, how about trying to create another exception? We want the user to supply a city name that can only be a string object. If they don't do this, we should throw an error if another data type is provided. Make sure to begin writing from the test, then run pytest to spot the test failure. After doing so, you can write the accompanying source code to make the test pass. One special note. In the original code, we expected a value error to be raised or a type error would be more appropriate. Here's one hint. Try adding validation logic to the instantiation method of the point class. Remember that you can add in the built-in breakpoint function so that you can examine the current variables and objects that you're able to access during your test run. This challenge should take you about five minutes. Good luck.