1. pytest development team
  2. pytest-dev
  3. pytest
  4. Issues

Issues

Issue #764 on hold

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

Tom V
created an issue

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.

Comments (5)

  1. Floris Bruynooghe

    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.

  2. Tom V reporter

    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!

  3. Floris Bruynooghe

    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?

  4. Log in to comment