Skip to content

Protocol method placeholders marked as untested #1616

@andrewlalis

Description

@andrewlalis

Originally posted in pytest-cov as issue 593

Describe the bug
When computing the coverage of a project, I am getting cases where the placeholder body of a protocol method is considered as untested code. I would expect that the body of protocol methods would not be marked as untested.

To Reproduce
Consider the following python code:

from typing import Protocol

class Example(Protocol):
    def do_something() -> None:
        ...

Using:

  • Python version 3.11
  • pytest version 7.3.0
  • pytest-cov version 4.0.0
  • coverage version 7.2.2

Running coverage on a project containing the above Example protocol will produce a report indicating that the line containing the ... placeholder is untested. I believe that this is incorrect, as it is impossible and useless to test the existence of a placeholder statement in a protocol's method definition.

Expected behavior
I would expect coverage to omit marking the lines in the above code snippet as untested.

Additional context
PEP 544 - Protocols

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions