Skip to content

regression in pytest 8.1.1: module level setup function doesn't seem to be run #12113

Closed
@neutrinoceros

Description

@neutrinoceros

The following is a minimal reproducer for a real-life application in yt:

# test.py
obj = None
def setup():
    global obj
    obj = []

def test_foo():
    assert len(obj) == 0

This test worked as expected until pytest 8.0.2 but fails with version 8.1.1 as

=========================== test session starts ===========================
platform darwin -- Python 3.12.2, pytest-8.1.1, pluggy-1.4.0
rootdir: /private/tmp
collected 1 item

test.py F                                                           [100%]

================================ FAILURES =================================
________________________________ test_foo _________________________________

    def test_foo():
>       assert len(obj) == 0
E       TypeError: object of type 'NoneType' has no len()

test.py:7: TypeError
========================= short test summary info =========================
FAILED test.py::test_foo - TypeError: object of type 'NoneType' has no len()
============================ 1 failed in 0.01s ===========================

which seems to indicate that the setup function wasn't run ahead of the test.
Possibly related to #12011 or how it was resolved ?

exact env:

Package   Version
--------- -------
iniconfig 2.0.0
packaging 24.0
pluggy    1.4.0
pytest    8.1.1

Bug seen on MacOS 14 and ubuntu-latest on GHA

  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions