2015-10-06 65 views
0

,但在這個項目中,測試是在常規的模塊,而不是模塊標記test_stuff.pyPy.test不會找到我使用的是<code>pytest</code>測試

我試圖通過change the test discovery在根加入pytest.ini文件

[pytest] 
python_files = *.py 
python_functions=test_* 

當我運行測試,仍然沒有發現:

$ py.test 
================================ test session starts ================================ 
platform linux2 -- Python 2.7.6 -- py-1.4.20 -- pytest-2.5.2 
collected 0 items 

================================= in 0.03 seconds ================================== 

我的佈局我的項目有以下內容很難簡化:

$ ls 
foo.py 
pytest.ini 

其中foo.py包含:

def add(a, b): 
    return a+b 

def test_add(): 
    assert 4 == add(2, 2) 
+0

@jonrsharpe期待它沒有拿起'.ini',這就是關鍵。我已經添加了細節。 –

+0

它似乎根據文檔類正在收集,而不是函數http://pytest.org/latest/customize.html#confval-python_classes – Srgrn

+0

@jonrsharpe我看不出你的例子與我的不同。同樣的結果。 –

回答

0

升級!

$ sudo pip install pytest --upgrade 

此設置適用於pytest 2.8,失敗2.5。

+1

至於爲什麼:'python_functions'和'python_classes'(而不是'python_files')的glob語法僅在v2.7.0中引入 - 請參閱https://pytest.org/latest/announce/release-2.7.0 .html#比較2-6-4,https://github.com/pytest-dev/pytest/issues/600 – jonrsharpe

相關問題