Content-Length: 300468 | pFad | https://github.com/python/cpython/issues/120665

ad unittest loaders should avoid loading test cases that are abstract base classes · Issue #120665 · python/cpython · GitHub
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

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions









    ApplySandwichStrip

    pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


    --- a PPN by Garber Painting Akron. With Image Size Reduction included!

    Fetched URL: https://github.com/python/cpython/issues/120665

    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy