pytest-django icon indicating copy to clipboard operation
pytest-django copied to clipboard

alternative for "ignore_template_errors"

Open jedie opened this issue 6 years ago • 2 comments
trafficstars

The pytest marker ignore_template_errors will deactivate the InvalidVarException but the string_if_invalid value is still not the default empty string. So it may have some site effects, e.g.: calling manage command "check" will fail:

E           django.core.management.base.SystemCheckError: SystemCheckError: System check identified some issues:
E           
E           ERRORS:
E           ?: (templates.E002) 'string_if_invalid' in TEMPLATES OPTIONS must be a string but got: <pytest_django.plugin._fail_for_invalid_template_variable.<locals>.InvalidVarException object at 0x7f2247a94b70> (InvalidVarException).

What's about a alternative solution like:

@pytest.fixture(scope="function")
def deactivate_fail_on_template_vars():
    template_settings = copy.deepcopy(settings.TEMPLATES)
    template_settings[0]["OPTIONS"]["string_if_invalid"] = ""

    with override_settings(TEMPLATES=template_settings):
        yield

This works for me ;) Should i create a pull request and replace ignore_template_errors?

jedie avatar Jun 28 '19 10:06 jedie

So it may have some site effects, e.g.: calling manage command "check" will fail:

But only under test, right?

deactivate_fail_on_template_vars

This is meant to be used when using the check command etc under test then?

blueyed avatar Jun 28 '19 14:06 blueyed

ignore_template_errors doesn't disable the entire mechanism, it only makes it not fail, but the Undefined template variable '{}' in '{}' errors are still shown. Setting it to '' will disable it.

We can possibly add a parameter to the ignore_template_errors mark to use a custom string. Not sure if it's worth it, usually django checks are not run as tests.

bluetech avatar Oct 16 '20 22:10 bluetech