How to get coverage report for Python enum entries?

29 Views Asked by At

Is it possible to check whether all of the values of an Enum have been used? For example, given the following code:

from enum import Enum


class Prefix(Enum):
    FORMAL = "Hello"
    INFORMAL = "Hi"


def hello(name):
    return f"{Prefix.FORMAL.value}, {name}!"


def test_hello_with_sample_name() -> None:
    assert hello("Alice") == "Hello, Alice!"

Is it possible to configure Python's coverage module (or some other test runner) to report that line 6, INFORMAL = "Hi", is unused?

0

There are 0 best solutions below