I have a functional test 'y1.py' which I am trying to pass arguments to, from within a python/django function. Inside the calling function I have:
import unittest, sys
import ft1.y1
ft1.y1.testVars = [1, 2, 3, "foo"]
unittest.main(module=ft1.y1, argv=sys.argv[:1], exit=False)
based on h.ttp://stackoverflow.com/questions/2812132/how-to-pass-variables-using-unittest-suite
y1.py:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
import unittest, time, re
class Y1(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "https://www.yahoo.com/"
self.verificationErrors = []
self.accept_next_alert = True
print('tvars' +self.testVars )
....................
if __name__ == "__main__":
unittest.main()
I'm getting :
Traceback (most recent call last):
File "F:\envs\r1\driver1\ft1\y1.py", line 17, in setUp
print('tvars '+ y1.testVars )
AttributeError: type object 'y1' has no attribute 'testVars'
----------------------------------------------------------------------
Ran 1 test in 2.330s
FAILED (errors=1)
[02/Feb/2014 23:59:42] "GET /runtest/ HTTP/1.1" 200 7
How can I fix this?
EDIT:
As suggested I changed the line to :
print('tvars' + sys.module[__name__].testVars )
I'm getting:
E
======================================================================
ERROR: test_y1 (ft1.y1.y1)
----------------------------------------------------------------------
Traceback (most recent call last):
File "F:\envs\r1\driver1\ft1\y1.py", line 17, in setUp
print('tvars' + sys.module[__name__].testVars )
AttributeError: 'module' object has no attribute 'module'
----------------------------------------------------------------------
Ran 1 test in 2.981s
FAILED (errors=1)