pytest icon indicating copy to clipboard operation
pytest copied to clipboard

Errors in teardown_module erroneously attached to last executed test

Open pytestbot opened this issue 10 years ago • 5 comments

UPDATE 2024-17-06: this bug is still alive and kicking

Originally reported by: David MacIver (BitBucket: david_maciver_, GitHub: david_maciver_)


Consider a test suite like the following:

#!python

def teardown_module(module):
    assert False


def test_stuff():
    pass


def test_things():
    pass

The result is:

collected 2 items 

test_module_teardown.py ..E

=================================================== ERRORS ===================================================
______________________________________ ERROR at teardown of test_things ______________________________________
Traceback (most recent call last):
  File "/home/david/projects/hypothesis/test_module_teardown.py", line 2, in teardown_module
    assert False
AssertionError: assert False


In particular the "ERROR at teardown of test_things" bit is weird. It's not a big deal, but it would be better if this didn't get attached to the test which just happens to have run last but was instead marked as belonging to the module.


  • Bitbucket: https://bitbucket.org/pytest-dev/pytest/issue/657

pytestbot avatar Jan 14 '15 09:01 pytestbot

:+1:

ghostsquad avatar Aug 05 '15 19:08 ghostsquad

Unfortunately this is currently by design of setupstate

RonnyPfannschmidt avatar Jan 01 '16 15:01 RonnyPfannschmidt

This has tripped me up before as well, but it shouldn't block 3.0.

The-Compiler avatar Aug 05 '16 10:08 The-Compiler

I was curious. It's still a thing with the current code:

(pytest) √ 2024-pytest-sprint/reproducers % 
cat test_657.py   
def teardown_module(module):
    assert False

def test_stuff():
    pass

def test_things():
    pass
(pytest) √ 2024-pytest-sprint/reproducers % 
pytest test_657.py
================================================= test session starts ==================================================
platform darwin -- Python 3.11.9, pytest-8.3.0.dev105+g5037f8d11, pluggy-1.5.0
rootdir: /Users/ob/Library/CloudStorage/Dropbox/projects/2024-pytest-sprint/reproducers
collected 2 items                                                                                                      

test_657.py ..E                                                                                                  [100%]

======================================================== ERRORS ========================================================
___________________________________________ ERROR at teardown of test_things ___________________________________________

module = <module 'test_657' from '/Users/ob/Library/CloudStorage/Dropbox/projects/2024-pytest-sprint/reproducers/test_657.py'>

    def teardown_module(module):
>       assert False
E       assert False

test_657.py:2: AssertionError
=============================================== short test summary info ================================================
ERROR test_657.py::test_things - assert False
============================================== 2 passed, 1 error in 0.02s ==============================================

obestwalter avatar Jun 16 '24 17:06 obestwalter

This isn't specific to teardown_module, it also happens with fixtures (see #12734). From what I could gather, the breaking changes proposed in #895 would fix this?

The-Compiler avatar Aug 26 '24 17:08 The-Compiler