Parametrized tests funcargs missing on 'pytest_collection_modifyitems' hook (pytest 2.5.2)
Hi, For testing purposes I use hook 'pytest_collection_modifyitems' to get values of all arguments passed in parametrized test function, e.g.: *def pytest_collection_modifyitems(items):* * for item in items:* * print item.funcargs* with code execution example: *{'doc': ['doc_1'], 'name': 'test_1'}* *{'doc': ['doc_2'], 'name': 'test_2'}* *{'doc': ['doc_3'], 'name': 'test_3'}* Example of code usage is attached. It works fine with pytest version 2.4.2. However while moving to pytest version 2.5.2 i faced the following issue: *item.funcargs *dictionary is empty {} {} {} Could you please clarify how can I get *funcargs *in the 'pytest_collection_modifyitems' hook in pytest 2.5.2? Thanks in advance! Anton
Hi Anton, On Wed, Feb 26, 2014 at 13:19 +0200, Anton P wrote:
Hi,
For testing purposes I use hook 'pytest_collection_modifyitems' to get values of all arguments passed in parametrized test function, e.g.:
*def pytest_collection_modifyitems(items):* * for item in items:* * print item.funcargs*
with code execution example:
*{'doc': ['doc_1'], 'name': 'test_1'}* *{'doc': ['doc_2'], 'name': 'test_2'}* *{'doc': ['doc_3'], 'name': 'test_3'}*
Example of code usage is attached. It works fine with pytest version 2.4.2. However while moving to pytest version 2.5.2 i faced the following issue: *item.funcargs *dictionary is empty {} {} {}
Could you please clarify how can I get *funcargs *in the 'pytest_collection_modifyitems' hook in pytest 2.5.2?
"item.funcargs" is now filled during test execution time, not test execution time. I think it was never documented either way so i don't regard it as an API promise. Also, funcargs/fixtures are setup during test execution so we can not generally make values available during collection. With 2.5.2 you might still fish for the values, i think it's on 'item.callspec.funcargs' or so but again, no promise. holger
Thanks in advance! Anton
import pytest
@pytest.mark.trylast def pytest_collection_modifyitems(items): for item in items: print item.funcargs
import pytest
class TestClass():
argvals = [("test_1", ["doc_1", ]), ("test_2", ["doc_2", ]), ("test_3", ["doc_3", ])]
@pytest.mark.parametrize("name, doc", argvals, ids=[x[0] for x in argvals]) def test_params(self, name, doc): pass
_______________________________________________ Pytest-dev mailing list Pytest-dev@python.org https://mail.python.org/mailman/listinfo/pytest-dev
On Mon, Mar 03, 2014 at 12:32 +0100, Jurko Gospodnetić wrote:
Hi.
"item.funcargs" is now filled during test execution time, not test execution time.
Dang... this made me go into an infinite loop... took me 4 readings through the same sentence to finally see the problem. :-D
sorry -- for others: "filled during test execution, not test collection time". holger
Best regards, Jurko Gospodnetić
_______________________________________________ Pytest-dev mailing list Pytest-dev@python.org https://mail.python.org/mailman/listinfo/pytest-dev
participants (3)
-
Anton P -
holger krekel -
Jurko Gospodnetić