我遇到了这个py.test问题报告中描述的问题: https://bitbucket.org/hpk42/pytest/issue/27/collectonly-doesnt-respect-k
以下是Jenkins控制台的结果: ~~~~~~~~~~~~~~~~~~ + py.test -v -k test_example --junitxml = functionaltests / reports / res.xml =============================测试会话开始================== ============ platform linux2 - Python 2.7.3 - pytest-2.3.4 - /var/lib/jenkins/shiningpanda/jobs/9df20569/virtualenvs/701cc1aa/bin/python2.7 插件:xdist 收集...收集3件/ 1错误
functionaltests/test_example.py:40: test_data[apple] PASSED
functionaltests/test_example.py:40: test_data[pear] PASSED
functionaltests/test_example.py:40: test_data[berry] PASSED
==================================== ERRORS ====================================
___________ ERROR collecting functionaltests/test_smm_healthcheck.py ___________
functionaltests/test_smm_healthcheck.py:2: in <module>
> import models.SMMMicrosites as site_data
E ImportError: No module named models.SMMMicrosites
generated xml file: /var/lib/jenkins/workspace/WT/functionaltests/reports/res.xml
====================== 3 passed, 1 error in 0.05 seconds =======================
Build step 'Virtualenv Builder' marked build as failure
Recording test results
Finished: FAILURE
~~~~~~~~~~~~~~~~~~
不应收集或执行测试模块“test_smm_healthcheck.py”。修复程序 - 已解决 - 尚未发布?我正在运行py.test版本2.3.4。
答案 0 :(得分:1)
“-k”标志不会影响收集的内容 - 只会报告--collectonly报告的内容。所以你不能用它来防止收集。您可以使用--ignore = path(一次或多次)来阻止收集。