1

the is the function I want to set a test for, and it is in the .py file name_function.py

def get_formatted_name(first, last):
    """generate a neatly formatted full name"""
    fullname = f"{first} {last}"
    return fullname.title()

The main programe:

import unittest
from name_function import get_formatted_name as gfn

class NamesTestCase(unittest.TestCase):
    """Test For 'name_function.py'."""
    def test_first_last_name(self):
        """Do names like 'Janis Joplin' work?"""
        formatted_name = gfn('janis', 'joplin')
        self.assertEqual(formatted_name, 'Janis Joplin')

I don't understand the block below

if __name__ == '__main__':
    unittest.main()
  • https://realpython.com/python-main-function/ – kol Mar 06 '21 at 18:40
  • `unittest.main()` runs the `main()` function of the `unittest` package which in the background checks all of the classes in the module and if any of them inherits from `unittest.TestCase` it'll be considered a test case to be run by the built-in runner of `unittest` package. It's used for simplicity if you want to run only tests for a single module. – Peter Badida Mar 06 '21 at 21:06

0 Answers0