Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overriding autouse fixture with a parametrized fixture does not work #1601

Closed
astraw38 opened this issue Jun 9, 2016 · 2 comments
Closed
Labels
topic: fixtures anything involving fixtures directly or indirectly type: bug problem that needs to be addressed

Comments

@astraw38
Copy link

astraw38 commented Jun 9, 2016

If you try to override an autouse fixture w/ a parametrized fixture in a subdirectory's conftest.py, pytest will raise a ValueError "Duplicate '<fixture_name>'". This will work if you either do not have the first fixture set to Autouse, or if the second fixture is not parametrized.

Main conftest.py:

import pytest

@pytest.fixture(scope='function', autouse=True)
def myf():
    return 'f'

subdirectory/conftest.py::

import pytest

@pytest.fixture(scope='function', params=["F", 'f'])
def myf(request):
    return request.param

subdirectory/test_me.py::

def testme(myf):
    assert myf == 'f'

Returns the following error:

_________________________________________________________________________________________________________________________ ERROR collecting test_me.py _________________________________________________________________________________________________________________________
/home/astraw/workspace/venvs/ltap/local/lib/python2.7/site-packages/_pytest/runner.py:150: in __init__
    self.result = func()
/home/astraw/workspace/venvs/ltap/local/lib/python2.7/site-packages/_pytest/main.py:435: in _memocollect
    return self._memoizedcall('_collected', lambda: list(self.collect()))
/home/astraw/workspace/venvs/ltap/local/lib/python2.7/site-packages/_pytest/main.py:315: in _memoizedcall
    res = function()
/home/astraw/workspace/venvs/ltap/local/lib/python2.7/site-packages/_pytest/main.py:435: in <lambda>
    return self._memoizedcall('_collected', lambda: list(self.collect()))
/home/astraw/workspace/venvs/ltap/local/lib/python2.7/site-packages/_pytest/python.py:605: in collect
    return super(Module, self).collect()
/home/astraw/workspace/venvs/ltap/local/lib/python2.7/site-packages/_pytest/python.py:459: in collect
    res = self.makeitem(name, obj)
/home/astraw/workspace/venvs/ltap/local/lib/python2.7/site-packages/_pytest/python.py:471: in makeitem
    collector=self, name=name, obj=obj)
/home/astraw/workspace/venvs/ltap/local/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py:724: in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
/home/astraw/workspace/venvs/ltap/local/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py:338: in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
/home/astraw/workspace/venvs/ltap/local/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py:333: in <lambda>
    _MultiCall(methods, kwargs, hook.spec_opts).execute()
/home/astraw/workspace/venvs/ltap/local/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py:595: in execute
    return _wrapped_call(hook_impl.function(*args), self.execute)
/home/astraw/workspace/venvs/ltap/local/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py:249: in _wrapped_call
    wrap_controller.send(call_outcome)
/home/astraw/workspace/venvs/ltap/local/lib/python2.7/site-packages/_pytest/python.py:330: in pytest_pycollect_makeitem
    res = list(collector._genfunctions(name, obj))
/home/astraw/workspace/venvs/ltap/local/lib/python2.7/site-packages/_pytest/python.py:491: in _genfunctions
    self.ihook.pytest_generate_tests(metafunc=metafunc)
/home/astraw/workspace/venvs/ltap/local/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py:724: in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
/home/astraw/workspace/venvs/ltap/local/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py:338: in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
/home/astraw/workspace/venvs/ltap/local/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py:333: in <lambda>
    _MultiCall(methods, kwargs, hook.spec_opts).execute()
/home/astraw/workspace/venvs/ltap/local/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py:596: in execute
    res = hook_impl.function(*args)
/home/astraw/workspace/venvs/ltap/local/lib/python2.7/site-packages/_pytest/python.py:1957: in pytest_generate_tests
    ids=fixturedef.ids)
/home/astraw/workspace/venvs/ltap/local/lib/python2.7/site-packages/_pytest/python.py:1029: in parametrize
    param_index)
/home/astraw/workspace/venvs/ltap/local/lib/python2.7/site-packages/_pytest/python.py:869: in setmulti
    self._checkargnotcontained(arg)
/home/astraw/workspace/venvs/ltap/local/lib/python2.7/site-packages/_pytest/python.py:852: in _checkargnotcontained
    raise ValueError("duplicate %r" %(arg,))
E   ValueError: duplicate 'myf'
=====================================================================
@diegorusso
Copy link
Contributor

diegorusso commented Jul 23, 2016

Hello, I'm not able to replicate the issue. Here the quick test I did

$ py.test
========================================================== test session starts ===========================================================
platform darwin -- Python 3.5.2, pytest-2.9.3.dev0, py-1.4.31, pluggy-0.3.1
rootdir: /Users/diegor/Developer/aaa, inifile: 
collected 2 items 

subdir/test_me.py F.

================================================================ FAILURES ================================================================
_______________________________________________________________ testme[F] ________________________________________________________________

myf = 'F'

    def testme(myf):
>       assert myf == 'f'
E       assert 'F' == 'f'
E         - F
E         + f

subdir/test_me.py:2: AssertionError
=================================================== 1 failed, 1 passed in 0.02 seconds ===================================================

Can you tell us more about your environment?

I've tested also with pytest 2.9.2 and it is working correctly.

Cheers

@bluetech
Copy link
Member

Closing per comment above which I can confirm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: fixtures anything involving fixtures directly or indirectly type: bug problem that needs to be addressed
Projects
None yet
Development

No branches or pull requests

4 participants