Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add disable_block_exclusion Option #1764

Closed
wants to merge 1 commit into from

Conversation

luskjh
Copy link

@luskjh luskjh commented Apr 20, 2024

Use case: I want coveragepy report the coverage of lines executed after Django has bootstrapped my application - this allows more accurate coverage reporting of things like class-based views, which always show 100% when the Django bootstrap process is included in the reporting. To do so, I've created a custom test runner in my project:

class CodeCoverageRunner(DiscoverRunner):
    ...

    def run_tests(self, test_labels, **kwargs):
        self._cov.start()

        super().run_tests(test_labels, **kwargs)

        self._cov.stop()
        self._cov.save()
        self._cov.report()

this works as expected, but (also, as expected), class / function definiton lines are not reported as being run, so when I exclude them (as well as import statements):

exclude_lines = [
    "import.*",
    "from.*import.*",
    "@.*",
    "def.*\\(.*\\).*:",
    "class.*\\(.*\\).*:",
]

I run into the problem that their body defintions also get excluded per current functionality. I'v added the disable_block_exclusion option to the [report] sectiont to allow for this functionality to be disabled.

First time contributing, read through Contributing to coverage.py to try and include everything necessary here.

Open to any feedbabck from the configuration value's name to why you may not want to accept this change into your project - I would find it very useful though!

@luskjh luskjh closed this by deleting the head repository May 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant