2016-05-23 55 views
2

有配置testconfig這樣我可以在命令行即傳遞URL「nosetests --tc = systest_url test_suit.py」傳遞一個URL來測試針對與鼻子testconfig

我需要一種方式在teamcity上執行構建時,針對開發和系統環境運行我的硒測試。我們的團隊決定使用python進行UI測試,並且我更喜歡Java人,我想知道插件是如何工作的,它看起來像我可以在yaml中存儲url,並將文件傳遞給--tc命令,但是不會'不像是會工作

我繼承的代碼如下所示:

URL = config['test' : 'https://www.google.com', ] 


class BaseTestCase(unittest.TestCase, Navigation): 
    @classmethod 
    def setUpClass(cls): 
     cls.driver = webdriver.Firefox() 
     cls.driver.implicitly_wait(5) 
     cls.driver.maximize_window() 

     cls.driver.get(URL) 

這顯然是行不通的

回答

1

使用nose-testconfig --tc選項可以覆蓋配置值。使用冒號將鍵與值分開。例如,

nosetests test.py --tc=url:dev.example.com 

將使值在config['url']中可用。

from testconfig import config 

def test_url_is_dev(): 
    assert 'dev' in config['url'] 
+0

謝謝,工作。我是否總是需要傳遞完整的網址。有沒有辦法在配置中定義url值?我想從配置文件,ini/yaml/json等獲取配置參數? – pythonist

+0

您可以傳遞任何值並將其解析爲您在設置方法中的喜好。 Testconfig確實也支持配置文件。看看Mauro Baraldi的[答案](http://stackoverflow.com/a/37390385/2027280)。 – sowa

1

有鼻子插件,該nosetest-config。您可以指定一些配置文件並將文件名傳遞給來自鼻子的--tc-file arg。

的config.ini

[myapp_servers] 
main_server = 10.1.1.1 
secondary_server = 10.1.1.2 

在您的測試文件,你可以加載配置。

test_app.py

from testconfig import config 

def test_foo(): 
    main_server = config['myapp_servers']['main_server'] 

比,調用鼻子ARGS

nosetests -s --tc-file example_cfg.ini 

如文檔所描述的,可以使用其他配置文件鍵入像YAML,JSON,甚至Python模塊。