[pytest-dev] Parametrized tests funcargs missing on 'pytest_collection_modifyitems' hook (pytest 2.5.2)

holger krekel holger at merlinux.eu
Mon Mar 3 12:07:45 CET 2014


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 at python.org
> https://mail.python.org/mailman/listinfo/pytest-dev



More information about the Pytest-dev mailing list