You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have some custom template tags and filters. When I disable django_coverage_plugin or downgrade to version 1.3.1, all the code in the templatetags directory is marked as covered, as expected, but as of version 1.4.1 only the function body is marked as covered (which is sort of impossible):
Thanks for your issue report. There have been a number of similar reports. Late last night I found a fix for at least one of the potential initialization issues. I expect to create a PR with that fix tonight
Background:
Since version 1.8, Django has been deferring initialization steps later and later in the process.
Since these changes are all internal to Django, they are not always mentioned in the various release notes, so there's a bit of "whack a mole" trying to find issues. And one-time initialization order issues are very hard to write unit tests for :( (See PR #37 for an attempt to test these paths)
@jclgoodwin Do you have a working example I could test against? Or at least your settings.TEMPLATES configuration?
I've added a template tag to my "insane_integration" test branch, but it works correctly.
Commenting out those two lines will prevent check_debug from executing. check_debug validates that the templates are (a) only using the standard Django Template Engine and (b) said engine is configured to be in debug mode.
Just my two cents. I am seeing this problem still with version 1.5.0 and Django 1.11.7 and coverage 4.4.1.
My observation is that if the custom tags are loaded into a template, it does not break anything. But when they are used, it leads to the whole template being marked as not covered at all.
Any idea how I can try to debug it? Unfortunately the project I am working on is not yet public.
I tried just adding # pragma: no coverage comments to the lines which were getting flagged as uncovered but I knew were obviously getting covered, IE, function definition lines, but that resulted in it skipping measuring whether the bodies of those functions were covered, effectively meaning the file was completely excluded.
So I spent the past 3 hours putting way too much effort into learning about the Coverage API and writing this function which is janky but seems to work for me:
It's not documented anywhere, but if you're measuring branch coverage, you must add arcs. Trying to add lines in instead gives back an error message.
This is all executed as part of a larger customer Django management function I've written... here's the lines around the one where this function is called:
defrunPythonTestsWithCoverage(self):
omitS=f'--omit={",".join(self.omitFiles+ [d+"/*"fordinself.omitDirs])}'run(['coverage', 'run', '--branch', "--source='.'", omitS, 'manage.py', 'test', 'myapp']).check_returncode()
self.fixTagCoverage() # <<<<<<<<<<<<<<<<<<<<<<<<<<< Where I call the function I just wroterun(['coverage', 'report', omitS, '-m', '--skip-covered', '--fail-under=100']).check_returncode()
run(['coverage', 'xml', omitS])
Activity
PamelaM commentedon Jan 30, 2017
Thanks for your issue report. There have been a number of similar reports. Late last night I found a fix for at least one of the potential initialization issues. I expect to create a PR with that fix tonight
PamelaM commentedon Jan 31, 2017
Could you try with PR #38?
Thanks.
Background:
Since version 1.8, Django has been deferring initialization steps later and later in the process.
Since these changes are all internal to Django, they are not always mentioned in the various release notes, so there's a bit of "whack a mole" trying to find issues. And one-time initialization order issues are very hard to write unit tests for :( (See PR #37 for an attempt to test these paths)
jclgoodwin commentedon Jan 31, 2017
No luck with #38. Commenting out lines 166 and 169 of plugin.py fixes the problem for me, though I don't understand why.
PamelaM commentedon Jan 31, 2017
@jclgoodwin Thanks for trying. I'll dig in some more and get back to you with another attempt.
<grumble>django gets more efficient at startup ... and more confusing</grumble> :)PamelaM commentedon Feb 1, 2017
@jclgoodwin Do you have a working example I could test against? Or at least your settings.TEMPLATES configuration?
I've added a template tag to my "insane_integration" test branch, but it works correctly.
Commenting out those two lines will prevent
check_debugfrom executing.check_debugvalidates that the templates are (a) only using the standard Django Template Engine and (b) said engine is configured to be in debug mode.jclgoodwin commentedon Feb 1, 2017
Yes: https://github.com/jclgoodwin/bustimes.org.uk/blob/master/buses/settings.py#L132
beda42 commentedon Feb 27, 2018
Hello,
Just my two cents. I am seeing this problem still with version 1.5.0 and Django 1.11.7 and coverage 4.4.1.
My observation is that if the custom tags are loaded into a template, it does not break anything. But when they are used, it leads to the whole template being marked as not covered at all.
Any idea how I can try to debug it? Unfortunately the project I am working on is not yet public.
TauPan commentedon May 5, 2019
I've just noticed that https://github.com/TauPan/pytest-django-xdist-cov-bug also seems to reproduce this issue. At least I noticed that I see no coverage for home.html which uses a custom template tag. (Thinking about filing pytest-dev/pytest-cov#285 against this repo, too, but that's still undecided.)
TaylorSMarks commentedon Apr 18, 2021
This is still an issue for me using:
What workarounds are available?
TaylorSMarks commentedon Apr 19, 2021
I tried just adding
# pragma: no coveragecomments to the lines which were getting flagged as uncovered but I knew were obviously getting covered, IE, function definition lines, but that resulted in it skipping measuring whether the bodies of those functions were covered, effectively meaning the file was completely excluded.So I spent the past 3 hours putting way too much effort into learning about the Coverage API and writing this function which is janky but seems to work for me:
It's not documented anywhere, but if you're measuring branch coverage, you must add arcs. Trying to add lines in instead gives back an error message.
This is all executed as part of a larger customer Django management function I've written... here's the lines around the one where this function is called: