pytest-dev / pytest

The pytest framework makes it easy to write small tests, yet scales to support complex functional testing
https://pytest.org
MIT License
11.93k stars 2.65k forks source link

Errors in teardown_module erroneously attached to last executed test #657

Open pytestbot opened 9 years ago

pytestbot commented 9 years ago

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

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


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.


ghostsquad commented 9 years ago

:+1:

RonnyPfannschmidt commented 8 years ago

Unfortunately this is currently by design of setupstate

The-Compiler commented 8 years ago

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

obestwalter commented 3 months ago

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 ==============================================
The-Compiler commented 1 month ago

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?