Skip to content

pytest 8.0.1 regression: setup_module is not run with --doctest-modules #12011

Closed
@lesteve

Description

@lesteve

It seems like setup_module is not being run in 8.0.1 when using --doctest-modules. This works fine with 8.0.0.

This was seen in scikit-learn/scikit-learn#28461.

To reproduce:

# test.py
CONSTANT = 0

def setup_module():
    global CONSTANT
    CONSTANT = 1


def test():
    assert CONSTANT == 1
pytest --doctest-modules test.py

Expected output: no failures

Actual output: failure

❯ pytest --doctest-modules test.py
======================================== test session starts ========================================
platform linux -- Python 3.12.2, pytest-8.0.1, pluggy-1.4.0
rootdir: /tmp/test
collected 1 item                                                                                    

test.py F                                                                                     [100%]

============================================= FAILURES ==============================================
_______________________________________________ test ________________________________________________

    def test():
>       assert CONSTANT == 1
E       assert 0 == 1

test.py:9: AssertionError
====================================== short test summary info ======================================
FAILED test.py::test - assert 0 == 1
========================================= 1 failed in 0.01s =========================================

❯ pip list              
Package    Version
---------- -------
iniconfig  2.0.0
packaging  23.2
pip        24.0
pluggy     1.4.0
pytest     8.0.1
setuptools 69.1.0
wheel      0.42.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    plugin: doctestsrelated to the doctests builtin plugintype: bugproblem that needs to be addressedtype: regressionindicates a problem that was introduced in a release which was working previously

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions