Skip to content

pytest_report_header from conftest.py not collected, in contradiction with documented behavior #14557

@neutrinoceros

Description

@neutrinoceros
  • a detailed description of the bug or problem you are having
  • output of pip list from the virtual environment you are using
  • pytest and operating system versions
  • minimal example if possible

Given the following source tree

src
└── tst
    ├── __init__.py
    ├── py.typed
    └── tests
        ├── conftest.py
        └── test_foo.py

and

# src/tst/tests/conftest.py
def pytest_configure(config):
    print("custom pytest_configure called !")

def pytest_report_header(config, start_path):
    1/0

(the rest of the contents doesn't matter)

I would expect both my custom pytest_configure and pytest_report_header impls to be called, but only the former is

❯ pytest
========================== test session starts ==========================
platform darwin -- Python 3.14.4, pytest-9.0.3, pluggy-1.6.0
rootdir: /private/tmp/tst
configfile: pyproject.toml
collecting ... custom pytest_configure called !
collected 1 item                                                        

src/tst/tests/test_foo.py .                                       [100%]

=========================== 1 passed in 0.00s ===========================

I can reproduce this without anything on my env but pytest and its own dependencies:

Package   Version
--------- -------
iniconfig 2.3.0
packaging 26.2
pluggy    1.6.0
pygments  2.20.0
pytest    9.0.3

reproduced on Macos Tahoe and ubuntu 24.04

The documentation says the following about pytest_configure

This hook is only called for initial conftests.

And the linked paragraph says this about "initial conftests"

for each test path, load conftest.py and test*/conftest.py relative to the directory part of the test path

which reads to me like it should include src/tst/tests/conftest.py, but it seems that it doesn't ?

Seems to me at least one of the following is true:

  • there is a bug in how initial conftests are processed
  • the documentation is incorrect
  • I don't understand what a "test path" means (FTR, I assume this refers to the path of any test module)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions