Q:

Python Unittest runs main function

Below is the how the program is set up. I have a UI that is (naturally) waiting for user input.    
root = Tk()
root.title("This space intentionally left blank")
mainFrame = Frame(root)
mainFrame.grid(column=1, row=2)
sideFrame=Frame(root)
sideFrame.grid(column=2, row=2)
topLabelFrame=Frame(root)
topLabelFrame.grid(column=1, row=1, columnspan=99)
main()
root.mainloop()

This is my unit test:
from unittest import TestCase
from AL2.AutoLinker2_0 import InputProcessor

    class TestInputProcessor(TestCase):

        def test_tokenize(self):
            IP = InputProcessor("")
            self.assertEqual(IP.tokenize("elbow mac"), ["elbow", "mac"])

When I run, my UI pops up and hangs up the unit tests until I close the UI.
I'm new to unit testing, but my understanding was that a unit test should only test the class and shouldn't need to run the entire program. Is this me not understanding, or is this maybe an issue with the IDE (pycharm), or is my program set up wrong?
Thanks!

A:

When importing a Python file as a module any code in the global scope will be executed upon parsing the file. This also applies to any code inside a class.
To allow your file to be both imported and callable, you need to use:
#!/usr/bin/python3
x = 1
y = 3

if "__name__" == "__main__":
    print(x+y)

__name__ always contains the name of the current module, except when a module is being executed, in this case, it will have the name "__main__"
For more info see: http://effbot.org/pyfaq/tutor-what-is-if-name-main-for.htm or https://www.ibiblio.org/swaroopch/byteofpython/read/module-name.html

