I have encountered the problem described in this py.test problem report:
https://bitbucket.org/hpk42/pytest/issue/27/collectonly-doesnt-respect-k
These are the results from the Jenkins console:
~~~~~~~~~~~~~~~~~~
+ py.test -v -k test_example –junitxml=functionaltests/reports/res.xml
============================= test session starts ==============================
platform linux2 — Python 2.7.3 — pytest-2.3.4 — /var/lib/jenkins/shiningpanda/jobs/9df20569/virtualenvs/701cc1aa/bin/python2.7
plugins: xdist
collecting … collected 3 items / 1 errors
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
~~~~~~~~~~~~~~~~~~
The test module “test_smm_healthcheck.py” should not be collected or executed. Has the fix — this is resolved — not been released? I’m running py.test version 2.3.4.
The “-k” flag does not influence what is collected – only what is reported with –collectonly. So you can’t use it to prevent collection. You can use –ignore=path (once or multiple times) to prevent collection.