Unittest: ignore test cases that are also ABC

You’re somewhat missing the point of the replies. One of the most important things needed with a proposal is an explanation of why it’s needed. That involves exploring what the problem is, and how or if it can be solved without changing the language. Remember, it’s you who needs to persuade us that your proposal is worthwhile.

To that end, I tried your example, and I couldn’t get the error you claimed. I needed to create dummy classes for BackendInterface, MemoryBackend and DiskBackend, but having done so, mypy didn’t give any errors. So the first thing you need to do is give an easier to reproduce example of the problem you’re trying to solve.

Then you need to be prepared to give a fair response to the various alternatives proposed. You’ve not responded to my suggestion of # type: ignore yet, and @JamesParrott suggested a class factory, which you dismissed with (essentially) the reponse that you don’t like that approach. But class factories or subtests are the standard way of writing parametrised tests in unittest, so simply dismissing those isn’t really a fair response.

For reference, using subtests would look something like this (warning: untested code):

backend_types: list[BackendInterface] = [MemoryBackend, DiskBackend]
class BackendTests(TestCase):
    def test_read(self):
        for backend_type in backend_types:
            with self.subTest(backend_type=backend_type)
                backend = backend_type()
                self.assertEqual(backend.read(), "42")
1 Like