![](/img/trans.png)
[英]Is there a way to get python's nose module to work the same in __main__ and on the command line?
[英]nose framework command line regex pattern matching doesnt work(-e,-m ,-i)
python nosetest框架有一些命令行選項,可以包含,排除和匹配可以分別包含/排除和匹配的測試的正則表達式。
但是它們似乎沒有正常工作。
[kiran@my_redhat test]$ nosetests -w cases/ -s -v -m='_size'
----------------------------------------------------------------------
Ran 0 tests in 0.001s
OK
[kiran@my_redhat test]$ grep '_size' cases/test_case_4.py
def test_fn_size_sha(self):
正則表達式匹配鼻子框架的語義是否有問題?
Nosetests的-m參數用於匹配目錄, 文件名 ,類和函數。 ( 請參閱鼻子文檔對此參數的說明 )在您的情況下,測試文件(test_case_4.py)的文件名與-m匹配表達式(_size)不匹配,因此永遠不會打開。
您可能會注意到,如果你強迫鼻子打開你的測試文件,它只能運行指定的測試:
nosetests -sv -m='_size' cases/test_case_4.py
通常,當我想匹配特定測試或測試子集時,我使用--attrib插件 ,它在默認的鼻子安裝中可用。 您可能還想嘗試排除與某些模式匹配的測試。
在指定正則表達式時嘗試刪除'=':
$ nosetests -w cases/ -s -v -m '_size'
或保持'='並拼出 - 匹配:
$ nosetests -w cases/ -s -v --match='_size'
Nose可能使用Python的re.match
或類似的東西,這需要在字符串的開頭匹配。 _size
不匹配,因為函數名test_fn_size_sha
不以正則表達式_size
。
嘗試使用從頭開始匹配的正則表達式:
nosetests -w cases/ -s -v -m='\w+_size'
這適合我。
nosetests --collect-only test_mytest\test_category --exclude=test_.*Pin
在這里,我排除了測試用例名稱中包含單詞“Pin”的所有測試。
注意:在我的情況下,所有測試用例名稱都以test_開頭。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.