I am learning testing using unittest module. At the end of a test script, there is this code
if __name__ == '__main__': unittest.main()
I get that it is asking if the script is running as a main program. But I wonder what defines a main program? unittest module and a class being test are imported. Is it that the test class that implements the test to the tested class is within the script?
But most importantly, why do I need to write that code at the end?
Also I have a different question regarding dictionaries.
For ‘for’ looping dictionaries, it seems to need .value(), .keys(), .items(). These seem to convert dictionaries into lists. Does that mean ‘for’ loop only iterates lists?
I understand ‘for’ loop iterates dictionaries’ keys, but I wished to reach values directly. But it seems dictionaries have to be converted into lists first in order to reach values.
You must select a tag to post in this category. Please find the tag relating to the section of the course you are on E.g. loops, learn-compatibility
When you ask a question, don’t forget to include a link to the exercise or project you’re dealing with!
If you want to have the best chances of getting a useful answer quickly, make sure you follow our guidelines about how to ask a good question. That way you’ll be helping everyone – helping people to answer your question and helping others who are stuck to find the question and answer!