0

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)
0

1 Answer 1

1

If you are trying to make a reference to the module rather than the class (your testVars are on the module level) you should probably use sys.modules[__name__].testVars which makes:

print('tvars' +self.testVars )

Become:

print('tvars' + sys.modules[__name__].testVars )
Sign up to request clarification or add additional context in comments.

2 Comments

you perhaps really mean sys.modules? pluralized?
Thanks to both of you , I used print('tvars ' + str(sys.modules[name].testVars )) and it worked

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.