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

--fixtures doesn't display all fixtures from conftest.py in sub directories #764

Closed
pytestbot opened this issue Jun 8, 2015 · 4 comments
Labels
type: bug problem that needs to be addressed

Comments

@pytestbot
Copy link
Contributor

Originally reported by: Tom V (BitBucket: tomviner, GitHub: tomviner)


Sample project to reproduce:
https://github.com/tomviner/bug-report-pytest-fixtures-list

Given I have a project with two app folders. Both apps have test folders with a conftest.py that both define a fixture. Also both apps have test files that use the respective app's fixture.

i.e.:

(pytest-fixture-find)~/dev/pytest-fixture-find$ find -name conftest.py
./project/app1/tests/conftest.py
./project/app2/tests/conftest.py

(pytest-fixture-find)~/dev/pytest-fixture-find$ ack-grep --py --context 1 "def fix"
project/app1/tests/conftest.py
3-@pytest.fixture
4:def fixy1():
5-    pass

project/app2/tests/conftest.py
3-@pytest.fixture
4:def fixy2():
5-    pass

Yet when I run py.test --fixtures or py.test --fixtures --traceconfig I only see one of those fixtures:

$ py.test --fixtures --traceconfig
PLUGIN registered: <_pytest.python.FixtureManager instance at 0x7f2af6b43440>
=============== test session starts ===============
platform linux2 -- Python 2.7.8 -- py-1.4.28 -- pytest-2.7.1
using: pytest-2.7.1 pylib-1.4.28

...

rootdir: /home/me/dev/pytest-fixture-find, inifile:
PLUGIN registered: <module 'conftest' from '/home/me/dev/pytest-fixture-find/project/app1/tests/conftest.pyc'>
PLUGIN registered: <module 'conftest' from '/home/me/dev/pytest-fixture-find/project/app2/tests/conftest.pyc'>
collected 2 items

...

------------- fixtures defined from conftest --------------
fixy1
    project/app1/tests/conftest.py:4: no docstring available

================  in 0.01 seconds ============={}

fixy2 is not shown.

See https://github.com/tomviner/bug-report-pytest-fixtures-list for full output.


@pytestbot
Copy link
Contributor Author

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


Fixtures visibility is limited by the scope they are defined in, so: py.test --fixtures project/app1/tests/ should show you fixy1 while py.test --fixtures project/app2/tests should show you fixy2.

I'm actually surprised you get fixy1 from running it in just the root directory, if anything I was going to think that was the bug. I should point out that this is all just my opinion of how I thought it was meant to work, maybe I'm wrong.

@pytestbot
Copy link
Contributor Author

Original comment by Tom V (BitBucket: tomviner, GitHub: tomviner):


Interesting. I wondered if it might be that it stops at the first conftest.py it finds. But no, I tried adding a few more conftest.pys containing a fixture (on this branch):

$ find -name conftest.py
./conftest.py
./project/conftest.py
./app3/tests/conftest.py
./project/app1/tests/conftest.py
./project/app2/tests/conftest.py

So which are found now?

$ py.test --fixtures --traceconfig
PLUGIN registered: <_pytest.python.FixtureManager instance at 0x7f8f0bcb46c8>
=============== test session starts ===============
platform linux2 -- Python 2.7.9 -- py-1.4.28 -- pytest-2.7.1
using: pytest-2.7.1 pylib-1.4.28

...

rootdir: /home/me/dev/pytest-fixture-find, inifile:
PLUGIN registered: <module 'conftest' from '/home/me/dev/pytest-fixture-find/project/conftest.pyc'>
PLUGIN registered: <module 'conftest' from '/home/me/dev/pytest-fixture-find/app3/tests/conftest.pyc'>
PLUGIN registered: <module 'conftest' from '/home/me/dev/pytest-fixture-find/project/app1/tests/conftest.pyc'>
PLUGIN registered: <module 'conftest' from '/home/me/dev/pytest-fixture-find/project/app2/tests/conftest.pyc'>
collected 3 items

...

------------- fixtures defined from conftest --------------
fixy4
    conftest.py:4: no docstring available
fixy3
    app3/tests/conftest.py:4: no docstring available

================  in 0.02 seconds =============

You see fixy3 & fixy4 but not 1, 2 & 5. And ./conftest.py (fixy5) isn't listed as a "PLUGIN registered".

So I'm not quite sure what the rule is now!

@pytestbot
Copy link
Contributor Author

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


I suspect the precense of __init__.py makes a difference. With the
recommended test layout of:

project/
+- tests/
    +- conftest.py (fix_top)
    +- app1/
    |   +- __init__.py
    |   +- conftest.py (fix_app1)
    +- app2/
        +- __init__.py
        +- conftest.py (fix_app2)

I get this:

$ cd project/
$ py.test --fixtures
[...builtin...]
$ py.test --fixtures tests/
[...builtin...]
---------------------- fixtures defined from conftest ------------------
fix_top
    tests/conftest.py:5: no docstring available

$ py.test --fixtures tests/app1/
[...builtin...]
-------------------- fixtures defined from app1.conftest --------------
fix_app1
    tests/app1/conftest.py:5: no docstring available

--------------------- fixtures defined from conftest ------------------
fix_top
    tests/conftest.py:5: no docstring available

$ py.test --fixtures tests/app2/
[...builtin...]
-------------------- fixtures defined from app2.conftest ---------------
fix_app2
    tests/app2/conftest.py:5: no docstring available

----------------------- fixtures defined from conftest -----------------
fix_top
    tests/conftest.py:5: no docstring available

Which is what I would be expecting.

It seems like the lack of __init__.py files makes the module paths of all the tests collide and py.test no longer knows how to identify them properly?

@pytestbot pytestbot added the type: bug problem that needs to be addressed label Jun 15, 2015
@tomviner
Copy link
Contributor

ok, makes sense to me. Could you close this issue please @flub , I don't have perms as @pytestbot created it.

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

3 participants