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

Duplicate fixtures in complex projects #1082

Closed
hunse opened this issue Sep 28, 2015 · 3 comments
Closed

Duplicate fixtures in complex projects #1082

hunse opened this issue Sep 28, 2015 · 3 comments
Labels
topic: fixtures anything involving fixtures directly or indirectly type: bug problem that needs to be addressed type: regression indicates a problem that was introduced in a release which was working previously
Milestone

Comments

@hunse
Copy link
Contributor

hunse commented Sep 28, 2015

Related to #979, I think, or at least a similar error.

I have the following directory structure:

project/amodule/tests/conftest.py
project/amodule/tests/test_amodule.py
project/bmodule/tests/conftest.py
project/bmodule/tests/test_bmodule.py

where both the conftest files contain

def pytest_generate_tests(metafunc):
    if 'myfixture' in metafunc.fixturenames:
        metafunc.parametrize("myfixture", ['a', 'b', 'c'])

and both the test_*.py files contain

def test_generate_tests_fixtures(myfixture):
    print(myfixture)

When I run all the tests with py.test project from the root directory (the parent of project), I get the following error

================================================ test session starts ================================================
platform linux2 -- Python 2.7.6, pytest-2.8.1.dev1, py-1.4.30, pluggy-0.3.1
rootdir: /data/eric/src/pytest, inifile: tox.ini
collected 3 items / 1 errors 

project/bmodule/tests/test_bmodule.py ...

====================================================== ERRORS =======================================================
______________________________ ERROR collecting project/amodule/tests/test_amodule.py _______________________________
project/amodule/tests/conftest.py:3: in pytest_generate_tests
    metafunc.parametrize("myfixture", ['a', 'b', 'c'])
_pytest/python.py:1002: in parametrize
    param_index)
_pytest/python.py:842: in setmulti
    self._checkargnotcontained(arg)
_pytest/python.py:825: in _checkargnotcontained
    raise ValueError("duplicate %r" %(arg,))
E   ValueError: duplicate 'myfixture'
========================================= 3 passed, 1 error in 0.08 seconds =========================================

However, if I delete both the tests subdirectories so everything is up one level, then it works fine.

@hunse
Copy link
Contributor Author

hunse commented Sep 28, 2015

By the way, this is a regression (or at least a change in behaviour), which according to git bisect was caused by 32165d8.

@nicoddemus nicoddemus added the type: bug problem that needs to be addressed label Sep 28, 2015
@nicoddemus nicoddemus added this to the 2.8.2 milestone Sep 28, 2015
@nicoddemus
Copy link
Member

Thanks @hunse! 😄

@RonnyPfannschmidt RonnyPfannschmidt modified the milestones: 2.8.2, 2.8.3 Oct 10, 2015
@nicoddemus nicoddemus modified the milestones: 2.8.3, 2.8.4 Nov 23, 2015
@RonnyPfannschmidt RonnyPfannschmidt modified the milestones: 2.8.4, 2.8.5 Dec 6, 2015
@RonnyPfannschmidt RonnyPfannschmidt modified the milestones: 2.8.5, 2.8.6 Dec 14, 2015
@Zac-HD Zac-HD added type: regression indicates a problem that was introduced in a release which was working previously topic: fixtures anything involving fixtures directly or indirectly labels Oct 20, 2018
@Zac-HD
Copy link
Member

Zac-HD commented Nov 27, 2019

Closing in favor of #3966, which is more recent and more heavily discussed.

@Zac-HD Zac-HD closed this as completed Nov 27, 2019
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 type: regression indicates a problem that was introduced in a release which was working previously
Projects
None yet
Development

No branches or pull requests

4 participants