0
由於某種原因,我在嘗試使用命令行參數與我的unittests時出現問題。如何在unittest中使用命令行參數?
簡而言之,我想要的就是使用env與我所有的測試。我在這裏做錯了什麼?
# -*- coding: utf-8 -*-
import argparse
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
import unittest, time, re
class mySmokeTest(unittest.TestCase):
def __init__(self, args):
self.env = args.env
def setUp(self):
self.driver = webdriver.Firefox()
self.base_url = "http://google.com"
self.verificationErrors = []
self.accept_next_alert = True
def test_add_to_cart(self, env):
# open base page
driver = self.driver
driver.get("{0}".format(env))
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('env', default='environment to test against')
args = parser.parse_args()
env = args.env
runner = unittest.TextTestRunner()
itersuite = unittest.TestLoader().loadTestsFromTestCase(mySmokeTest)
runner.run(itersuite)
錯誤:
self.env = args.env
AttributeError: 'str' object has no attribute 'env'
我不知道你做錯了什麼,你告訴我們。你需要重讀[mcve]頁面,特別是關於錯誤的部分。 –
所以我正確地傳遞了參數? – david
我不知道,你有任何錯誤? –