mardi 24 février 2015

Selenium tests - Everything is printed all the time no matter what

This might sound like a very silly question but here it is:


I'm writing selenium tests in python, and basically my base test class looks like that:



chromedriver = "../selenium-tests/chromedriver"
os.environ["webdriver.chrome.driver"] = chromedriver

class TestsFoo(unittest.TestCase):
base_url = None
language = None

def setUp(self):
self.driver = webdriver.Chrome(chromedriver)
self.verificationErrors = []
self.accept_next_alert = True
self.driver.set_window_size(1100, 800)


Then all of my other test classes extend from that class. Example:



class TestsFooChild(TestsFoo):
def test_something(self):
driver = self.driver
driver.get("{}{}/myurl.html".format(
self.base_url,
self.language)
)
# do stuff

print driver.current_url
self.assertTrue(somethingTrue)

def tearDown(self):
self.driver.close()
self.driver.quit()


language and url are defined thanks to this:



if __name__ == "__main__":
TestsFoo.base_url = os.environ.get('URL')
TestsFoo.language = os.environ.get('LANGUAGE')
unittest.main()


So that's a lot of informations for a very very tiny question: When doing unittest, if you let a print somewhere, it'll only be printed if the test fails.


Then why in my case, are every prints printed no matter what the result of the test is? I only want to print my current_url when the test fails.


Also, I'm just looking at why it does that. I'm actively working on finding a way to only print it when my test fails. So that part is taken care of. But I'm curious..


Aucun commentaire:

Enregistrer un commentaire