blhsing · GitHub

Bug report

Bug description:

As reported in Discourse, loading a TestCase-derived subclass that is also an abstract base class like the following:

import unittest
from abc import ABC, abstractmethod
class FooBase(unittest.TestCase, ABC):
    @abstractmethod
    def test(self): ...
class Foo(FooBase):
    def test(self): pass
unittest.main()

would currently result in:

TypeError: Can't instantiate abstract class FooBase without an implementation for abstract method 'test'

We should make the unittest loaders avoid loading such test cases and methods from them.

CPython versions tested on:

3.12, CPython main branch

Operating systems tested on:

Linux, Windows

Linked PRs

Read the original on github.com ↗