2016-12-30 24 views
1

我是新來的單元測試和「即時試圖在Eclipse上運行一個pytest。我已經搜索了幾個小時,我似乎無法找出問題所在。我正在玩https://pytest.org網站的簡單示例。我的問題是pytest只是沒有在Eclipse中運行,我可以使用命令提示符下做測試,但我寧願讓控制檯窗口中的結果如何在Eclipse上運行pytest?

事情我都試過,但沒有工作;

  • 設置PyUnit測試轉輪到Py.test轉輪(而不是默認的Pydev測試轉輪)

在這種情況下,我得到了以下錯誤消息

usage: runfiles.py [options] [file_or_dir] [file_or_dir] [...] runfiles.py: error: unrecognized arguments: --verbosity inifile: None rootdir: C:\peepee\pytest\testing

  • 我已經詳細程度設置爲9(讀的地方,它的最大值)。沒有任何區別。

簡單的代碼,我試圖從http://pytest.org網站

def func(x): 
    return x + 1 

def test_answer(): 
    assert func(3) == 5 

作品通過CMD但不是在Eclipse上進行測試。

請大家幫忙,因爲我正在努力弄清楚這一點。在此先感謝

回答

-1

找到了一種替代方案。只需使用PyCharm IDE即可使pytest非常容易運行。運行任何測試之前,請確保執行以下配置。

  • 單擊「運行」選項卡。選擇「編輯配置」
  • 添加配置的「+」符號
  • 選擇「的Python測試」根據該「py.test」
  • 請務必填寫「目標」路徑和「工作目錄」

快樂的日子。現在你已經pytest與控制檯窗口

0

它沒有爲你工作,因爲你在參數文本字段左「--verbosity 0」上顯示的結果運行。我不知道爲什麼它不會被Eclipse自動擦除,但當您更改亞軍時,您還必須更改參數以反映您的首選測試運行器(本例中爲pytest)。

在全球範圍內對所有新配置:

  1. Window -> Preferences -> PyDev -> PyUnit
  2. Change the test runner to "py.test runner" and clear the parameters (or add the ones you prefer. Make sure they are valid flags for pytest.)

或者,如果你願意的話,手動爲每個新的運行配置

  1. Create a Python unittest run configuration
  2. Select the class you want to run and the project (if they are not already there)
  3. In the Arguments tab override the pyUnit preferences with a py.test runner (clean up the parameters and add whatever you want to add to pytest flags)