Skip to content

Fixture is not overriden in the child conftest.py when running individual test file #294

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

Closed
pytestbot opened this issue Apr 11, 2013 · 6 comments
Labels
type: bug problem that needs to be addressed

Comments

@pytestbot
Copy link
Contributor

Originally reported by: Oleg Pidsadnyi (BitBucket: olegp, GitHub: olegp)


If I have the package with the conftest.py:

#!python

from pytest import fixture

@fixture
def foo():
    return 'parent'

And I have subfolder with the conftest.py:

#!python

from pytest import fixture

@fixture
def foo():
    return 'child'

And the test_foo.py in the same subfolder:

#!python

def test_foo(foo):
    assert foo == 'child'

It works when I simply run py.test in the parent folder.

It doesn't work when I run py.test subfolder/test_foo.py

For some reason the value is 'parent', not 'child'


@pytestbot
Copy link
Contributor Author

Original comment by holger krekel (BitBucket: hpk42, GitHub: hpk42):


could you spell out the filenames and directory names?

Also do you have an init.py in your sub folder?

@pytestbot
Copy link
Contributor Author

Original comment by holger krekel (BitBucket: hpk42, GitHub: hpk42):


at best just make a zip/tar file to allow reproduction.

@pytestbot
Copy link
Contributor Author

Original comment by Oleg Pidsadnyi (BitBucket: olegp, GitHub: olegp):


Yes, it has init.py. The subfolder is just subfolder, doesn't matter.

It works when I run it from the 294 directory:

#!bash

cd 294
py.test

And it doesn't when:

#!bash

cd 294
py.test tests/subfolder/test_foo.py

@pytestbot
Copy link
Contributor Author

Original comment by Oleg Pidsadnyi (BitBucket: olegp, GitHub: olegp):


Holger, maybe you can give a little hint where to look at?
I've tried to debug and the fixturedefs were ordered reversed. Can you point to the place where is it being collected. We are really suffering from this bug. You also mentioned that there's some fork where it is addressed by some guy. Can we have a look?

@pytestbot
Copy link
Contributor Author

Original comment by holger krekel (BitBucket: hpk42, GitHub: hpk42):


The PR is living here: https://bitbucket.org/hpk42/pytest/pull-request/30/load-conftest-files-in-the-correct-order/diff . Would be good if you try it and maybe help to get it into mergeable state.

@pytestbot
Copy link
Contributor Author

Original comment by Floris Bruynooghe (BitBucket: flub, GitHub: flub):


This is now resolved (see issue300)

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

No branches or pull requests

1 participant