Skip to content

Losing coverage of Hypothesis-strategy-called code #317

@altendky

Description

@altendky

This is a followup from discussions in #280.

As of Hypothesis 3.29.0 in September, coverage data is no longer collected for code called from strategies. It seems to have changed in the first commit or two after 3.28.3 (HypothesisWorks/hypothesis@6e7a478 HypothesisWorks/hypothesis@d75ac34). This was done intentonially to reduce the run time of tests.

This was identified after adjusting handling of unspecified metadata in attr.ib() (#278). The tests had no coverage reported for the case of metadata being specified despite that being the case many times during a test run (hundreds?). A little test was added to satisfy the coverage report.

attrs/tests/test_make.py

Lines 848 to 858 in b3861d1

def test_metadata(self):
"""
If metadata that is not None is passed, it is used.
This is necessary for coverage because the previous test is
hypothesis-based.
"""
md = {}
a = attr.ib(metadata=md)
assert md is a.metadata

This does the job, so to speak, but it seems a bit odd to have hundreds of instances where metadata is being specified and only one reporting coverage. In no particular order, here are a few options.

  • Talk with Hypothesis about changing this back (they were open to discussion)
  • Adjust our strategies to generate parameters for attr.ib() calls instead of having them actually make the attr.ib() calls as they do now.
  • Setup isolated Hypothesis tests and separate 'regular' tests where only the 'regular' tests count towards coverage

There is some concern about using Hypothesis driven testing for coverage reports since Hypothesis can be inconsistent (I think that is what has been said). I am not sure why it's ok to trust Hypothesis will be consistent enough for functionality checks but not for coverage checks. With this issue being my first involvement with Hypothesis, perhaps I'm missing some of the implications and techniques of using it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ThinkingNeeds more braining.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions