1
There is little time that I am using Python and there are some things that I still get confused, my doubt is in this code:
import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
class PythonOrgSearch(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
def test_search_in_python_org(self):
driver = self.driver
driver.get("http://www.python.org")
self.assertIn("Python", driver.title)
elem = driver.find_element_by_name("q")
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
def tearDown(self):
self.driver.close()
if __name__ == "__main__":
unittest.main()
Why in the "if __name__ == "__main__":
" he did not urge the class PythonOrgSearch
and why when placing the command "unittest.main()
" he executed the actions of the class Pythonorgsearch? This way does not get more confused? Can anyone explain why he did it this way?
O "if name == "main":" is not in the class "Pythonorgsearch"
– Wictor Chaves
This has more to do with how the framework
unittest
is used than with codePython
pure– Jefferson Quesado
Agree with @Jeffersonquesado, try to change the class arguments to Object
– Dev
I understood that it is because of the framework, but I’m still having the same problem, if I find a code this way I won’t know that unittest.main() will run the Pythonorgsearch class, how can I identify it, without having to run the code.
– Wictor Chaves
Knowing the code is the only way. The library
unittest
does things that seem magical even, not following much the philosophy of "explicit is better than implicit".– Woss