2015-10-06 50 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

相关问题