[Python] pytest 執行時找不到任何要被測試的 test case?

[Python] pytest 執行時找不到任何要被測試的 test case?

今天想用 pytest 在 Mac 上寫一下 unit-testing 程式,

不過執行 pytest 時,pytest 卻始終找不到要被測試的函式:

testuser@localhost ~ $ pytest test_ut.py
=========================  test_ut.py  =========================
----------------------------------------------------------------------
Ran 0 tests in 0.000s
OK
*******************************************************************************

 

這實在是很奇怪,我在 test_ut.py 裡面是有定義 test_ 開頭的測試函式的,怎麼會找不到呢?

只不過我也很久沒有在 Mac 上執行 pytest,不能肯定之前究竟是不是好的…

看一下現在的 pytest,版本是 2.7.2:

testuser@localhost ~ $ pip freeze | egrep pytest
pytest==2.7.2

 

試了半天,加 pytest.ini、指定要跑的檔案等等,都沒有效果,

後來死馬當活馬醫,升級一下 pytest 看看:

sudo pip install -U pytest

 

結果就會動了!!真的是有點奇怪:

testuser@localhost ~ $ pytest test_ut.py
=================================================================== test session starts ====================================================================
platform darwin -- Python 2.7.12, pytest-3.0.3, py-1.4.31, pluggy-0.4.0
rootdir: /Users/testuser, inifile:
collected 3 items
test_ut.py ...
================================================================= 3 passed in 0.01 seconds =================================================================

 

目前會動的版本是 3.0.3:

testuser@localhost ~ $ pip freeze | egrep pytest
pytest==3.0.3

 

看來下次遇到東西不會動的時候,重開機/重新安裝/升級大法還是有效果的…

 

(本頁面已被瀏覽過 887 次)

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料