def test_pdb_teardown_called(pytester: Pytester, monkeypatch: MonkeyPatch) -> None:
    """Ensure tearDown() is always called when --pdb is given in the command-line.

    We delay the normal tearDown() calls when --pdb is given, so this ensures we are calling
    tearDown() eventually to avoid memory leaks when using --pdb.
    """
    teardowns: list[str] = []
    monkeypatch.setattr(
        pytest, "test_pdb_teardown_called_teardowns", teardowns, raising=False
    )

    pytester.makepyfile(
        """
        import unittest
        import pytest

        class MyTestCase(unittest.TestCase):

            def tearDown(self):
                pytest.test_pdb_teardown_called_teardowns.append(self.id())

            def test_1(self):
                pass
            def test_2(self):
                pass
    """
    )
    result = pytester.runpytest_inprocess("--pdb")
    result.stdout.fnmatch_lines("* 2 passed in *")
    assert teardowns == [
        "test_pdb_teardown_called.MyTestCase.test_1",
        "test_pdb_teardown_called.MyTestCase.test_2",
    ]
Ensure tearDown() is always called when --pdb is given in the command-line.

    We delay the normal tearDown() calls when --pdb is given, so this ensures we are calling
    tearDown() eventually to avoid memory leaks when using --pdb.
    
testing/test_unittest.py