我目前使用pytest來自動化我的測試套件。我有分散在幾個目錄,如下面的測試:pytest:使用關鍵字選項(-k)時不處理目錄樣式字符串
|-Root
| |-Dir1
| | |-Test1
| | |-Test2
| | |-Test3
| |-Dir2
| | |-Testa
| | |-Testb
| | |-Testc
| |-Dir3
| | |-TestI
| | |-TestII
| | |-TestIII
我希望能夠通過排除其他人來運行一組目錄的測試。某些目錄具有類似的名稱,如「test_set_1」和「test_set_1_extended」。我想排除「test_set_1」,但保留「test_set_1_extended」,所以我需要使用完整路徑作爲關鍵字。我注意到在使用關鍵字(-k選項)時,pytest不能很好地處理目錄結構字符串作爲參數。舉例來說,如果我嘗試windows風格
py.test -k "not (root\dir1 or dir2)"
我得到一個語法錯誤:
語法錯誤:意外的字符續行符
在另一方面之後,如果我嘗試UNIX風格
py.test -k "not (root/dir1 or dir2)"
我得到一個ZeroDivisionError:
ZeroDivisionError:i零
事情我已經試過nteger部門或模包括: 括在單或雙引號的目錄字符串:
py.test -k "not ('root/dir1' or dir2)"
py.test -k "not ("root/dir1' or dir2)"
使用單獨的 '-k的':
py.test -k "not root/dir1" -k not dir2)
使用當前目錄'。'
py.test -k "not (./root/dir1 or dir2)"
逃脫斜線:
py.test -k "not (root\\dir1 or dir2)"
py.test -k "not (root\/dir1 or dir2)"
這些都沒有解決的問題。有沒有人有任何建議如何讓pytest正確處理我的路徑字符串?