我正在使用Python 2.7。 我创建了以下脚本:
import unittest
from tests.selenium_test_base import SeleniumTestBase
import sys
class TestPrintArg(SeleniumTestBase):
def test_print_arg(self):
print "BEGIN: "+str(len(sys.argv))
for elements in sys.argv:
print elements
print "END:"
if __name__ == "__main__":
unittest.main()
我使用:python test_print_arg.py
但是如果我用参数执行:python test_print_arg.py arg1
我收到以下问题:
Traceback (most recent call last):
File "test_verify_page.py", line 19, in <module>
unittest.main()
File "C:\Python27\lib\unittest\main.py", line 94, in __init__
self.parseArgs(argv)
File "C:\Python27\lib\unittest\main.py", line 149, in parseArgs
self.createTests()
C:\stash\sxd_qa\tests\log_in>python test_verify_page.py arg1
BEGIN: 2
test_verify_page.py
arg1
END:
Traceback (most recent call last):
File "test_verify_page.py", line 19, in <module>
unittest.main()
File "C:\Python27\lib\unittest\main.py", line 94, in __init__
self.parseArgs(argv)
File "C:\Python27\lib\unittest\main.py", line 149, in parseArgs
self.createTests()
File "C:\Python27\lib\unittest\main.py", line 158, in createTests
self.module)
File "C:\Python27\lib\unittest\loader.py", line 130, in loadTestsFromNames
suites = [self.loadTestsFromName(name, module) for name in names]
File "C:\Python27\lib\unittest\loader.py", line 100, in loadTestsFromName
parent, obj = obj, getattr(obj, part)
AttributeError: 'module' object has no attribute 'arg1'
你可以帮帮我吗?如果我想使用参数,则不会启动浏览器。