Sunday, 6 February 2022

why __name__ is equal to __main__?

I understand that __main__ is the name of __main__.py, which in this case is test_employee. But what I don't understand is the unittest module and the class that I want to test are being imported. Then why __name__ is still same as __main__? As I understood, __name__ represents the modules being imported.

test_employee.py

import unittest

from employee import Employee

class TestEmployee(unittest.TestCase):

    def setUp(self):
        self.employee1 = Employee('June', 'July')
        self.employee2 = Employee('Jane', 'Marshal')
    
    def test_give_default_raise(self):
        self.assertEqual(5000, self.employee1.annual_salary)

    def test_give_custom_raise(self):
        self.employee2.give_raise(1000)
        self.assertEqual(6000, self.employee2.annual_salary)

if __name__ == '__main__':
    unittest.main()


from why __name__ is equal to __main__?

No comments:

Post a Comment