Specify function/method for coverage reports.

Issue #234 closed
Panos Mavrogiorgos created an issue

I think it would be useful if we could use a decorator at UnitTests that would specify which method/function is going to be tested. By doing so, we could get a more clear image from the test coverage report.

For example, in the following snippet, the coverage report should contain information only for the squared_abs method and not for the custom_abs.

class MyClass(object):
    def __init__(self):

    def custom_abs(self, value):
        if value > 0:
            return value
            return -value

    def squared_abs(self, value):
        abs_value = self.custom_abs(value)
        return abs_value ** 2

class MyClassTest(unittest.TestCase):
    def setUp(self):
        self.instance = MyClass()

    def test_MyClass_method2(self):
        assert self.instance.squared_abs(-2) == 4

Something similar can be done by profilehooks.

Comments (2)

  1. Ned Batchelder repo owner

    I have heard of people working on such a thing. I guess I'm skeptical that enough people would use it to make the development and documentation worth it. But I've been wrong before!

  2. Log in to comment