Skip to content

plugin not working with pytest #73

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

Closed
jnoortheen opened this issue Jun 3, 2020 · 8 comments
Closed

plugin not working with pytest #73

jnoortheen opened this issue Jun 3, 2020 · 8 comments

Comments

@jnoortheen
Copy link

Thanks for this great plugin. Now we don't have to worry about missing logic inside templates. I am not able to get it working with pytest.
I execute the tests like this

image

But the report always show 0% coverage for all the templates in the project.
image

has anyone used this plugin with pytest runner? am I missing something?

@mschoettle
Copy link

I started having this problem locally in my development environment (using venv) on Mac OS. It does not happen in my CI pipeline which runs in a Docker container. Both of them use the same requirements file with pinned versions.

@mschoettle
Copy link

@jnoortheen: Can you check whether your Django DEBUG setting is set to True? Mine accidentally was set to False. With debug enabled it works as expected.

@jnoortheen
Copy link
Author

@mschoettle I think that is my case too. The tests are always ran with DEBUG=False.

I haven't checked with DEBUG=True

@sparrowt
Copy link

sparrowt commented Apr 26, 2021

I had the same issue using pytest (0% coverage reported for everything) - as suggested above, setting Django DEBUG = True did work ✔ (after also adding django_debug_mode = true/keep to pytest.ini)

However I was under the impression that running tests with DEBUG = True is not best practice - is that a deliberate requirement of this plugin, or is it a bug that this plugin doesn't work with DEBUG = False?

EDIT: ah, it seems that the requirement is for DjangoTemplates 'debug' option to be True:

    TEMPLATES = [
        {
            'BACKEND': 'django.template.backends.django.DjangoTemplates',
            'OPTIONS': {
                'debug': True,
                ...

and the reason the main Django DEBUG setting works is because that affects the default value of DjangoTemplates 'debug'.

@sparrowt
Copy link

The real issue here (I think) is that check_debug never gets past if not settings.configured: when running under pytest (having attached a debugger), so it never gets as far as the code which should raise an exception saying "Template debugging must be enabled in settings".

Perhaps the note which #30 added to the "Changes" section of README.rst

Only the django.template.backends.django.DjangoTemplates template engine is
supported, and it must be configured with ['OPTIONS']['debug'] = True.

should be included in the main README, given that this is now archived away in HISTORY.rst so there is no mention of the template debugging requirement in the readme?

@jnoortheen
Copy link
Author

jnoortheen commented Apr 26, 2021

there is this PR #72 without much activity

@nedbat
Copy link
Owner

nedbat commented May 27, 2021

I can definitely add the note to the README. But I'd also be interested in making the warning visible in pytest. Can you give me a small project that demonstrates the problem?

@nedbat
Copy link
Owner

nedbat commented May 31, 2021

The README is updated in 3b7972f, and coverage.py will also now show the warning when running under pytest (as of nedbat/coveragepy@30c023b).

@nedbat nedbat closed this as completed May 31, 2021
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

No branches or pull requests

4 participants