Skip to content

Class cleanups in Python 3.8+ are not called #8032

@PetterS

Description

@PetterS

https://docs.python.org/3/library/unittest.html#unittest.TestCase.addClassCleanup

Did not see doClassCleanups mentioned anywhere in this repo, which is the method that should be called. See https://github.com/python/cpython/blob/0f221d09cad46bee38d1b7a7822772df66c53028/Lib/unittest/suite.py#L175

Repo:

import unittest

def cleanup():
    assert False

class MyTest(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.addClassCleanup(cleanup)
    
    def test_one(self):
        pass

With unittest:

.E
======================================================================
ERROR: tearDownClass (test_demo.MyTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/petter/source/pytesttest/test_demo.py", line 4, in cleanup
    assert False
AssertionError

----------------------------------------------------------------------
Ran 1 test in 0.000s

With Pytest:

collected 1 item

test_demo.py .                                                                                                                                                                       [100%]

==================================================================================== 1 passed in 0.03s ====================================================================================

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: enhancementnew feature or API change, should be merged into features branch

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions