Skip to content

Pytest does not show addClassCleanup errors #11728

Closed
@LukasJerabek

Description

@LukasJerabek
  • a detailed description of the bug or problem you are having
    Below in minimal example is a code that if I run with python, I get
Running test one
.E
======================================================================
ERROR: tearDownClass (__main__.SomeTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "tst.py", line 11, in clean_up_class
    raise AttributeError
AttributeError

----------------------------------------------------------------------
Ran 1 test in 0.001s

FAILED (errors=1)

which is fine, but if I run it with pytest I get:

==================================================================================== test session starts =====================================================================================
platform linux -- Python 3.8.18, pytest-7.4.3, pluggy-1.3.0
rootdir: /home/vagrant
collected 1 item                                                                                                                                                                             

tst.py .                                                                                                                                                                               [100%]

===================================================================================== 1 passed in 0.01s ======================================================================================

Without any sign of that an error has happend. Therefore it fail silently without anyone knowing something wrong happend.

Expected: Pytest shows error as well.

  • output of pip list from the virtual environment you are using
Package        Version
-------------- -------
exceptiongroup 1.2.0
iniconfig      2.0.0
packaging      23.2
pip            23.3.2
pluggy         1.3.0
pytest         7.4.3
setuptools     56.0.0
tomli          2.0.1

  • pytest and operating system versions
    pytest 7.4.3
    Centos7

  • minimal example if possible

import unittest


class SomeTest(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.addClassCleanup(cls.clean_up_class)
        
    @classmethod
    def clean_up_class(cls):
        raise AttributeError

    def test_one(self):
        print("Running test one")
        self.assertTrue(True)

if __name__ == '__main__':
    unittest.main()

Metadata

Metadata

Assignees

No one assigned

    Labels

    plugin: unittestrelated to the unittest integration builtin plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions