Skip to content

unittest loaders should avoid loading test cases that are abstract base classes #120665

Description

@blhsing

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    testsTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or error

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions