Skip to content

fixture hooks not running in packages #2361

@laurentsenta

Description

@laurentsenta

Hi there, thanks for maintaining such a great tool.

(pytest 3.0.7)

I have an unexplained behavior with conftest and fixtures,
I try to write a fixture that would depend on other fixtures optionally. If a test uses both the fixtures a and b for example, then the value of b would depend on the value of a.

I intend to use the pytest_fixture_setup hook, somehow, but:

  • When I define pytest_fixture_setup in tests/mypackage/conftest.py, it is never run.
  • When I define it in conftest.py (root, not in package), it is run.

This contradicts what I understood from:
https://docs.pytest.org/en/latest/writing_plugins.html#conftest-py-local-per-directory-plugins
(use conftest in the package where you need it, avoid non-package ones because imports are source of errors).

Even weirder, if you make an error on the hook parameters in tests/mypackage/conftest.py, pytest will raise an error. Fix the typo, the hook is ignored.

I pushed an empty project showing this issue:
https://github.com/lsenta/pytest-conftest-broken

Here's the output:

laurent at HALIX in ~/dev/pytest-conftest-broken on master
› tree
.
├── conftest.py
└── some_test
    ├── __init__.py
    ├── conftest.py
    └── test_x.py
laurent at HALIX in ~/dev/pytest-conftest-broken on master
› pytest -s
============================ test session starts =============================
platform darwin -- Python 3.6.0, pytest-3.0.6, py-1.4.32, pluggy-0.4.0
rootdir: /Users/laurent/dev/pytest-conftest-broken, inifile:
plugins: timeout-1.2.0
collected 2 items

some_test/test_x.py runtest_setup.package
runtest_setup.project
fixture_setup.project
.runtest_setup.package
runtest_setup.project
fixture_setup.project
.

========================== 2 passed in 0.01 seconds ==========================

the conftest is the same, so I expect to see fixture_setup.package at some point.

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: fixturesanything involving fixtures directly or indirectlytype: docsdocumentation improvement, missing or needing clarification

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions