Skip to content

Commit

Permalink
fix: Handle warnings for default_app_config (django-extensions#1654)
Browse files Browse the repository at this point in the history
- they are only defined for django versions < 3.2
  • Loading branch information
abhiabhi94 authored Apr 19, 2021
1 parent 912fcc8 commit a85bcac
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
9 changes: 8 additions & 1 deletion django_extensions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,11 @@ def get_version(version):

__version__ = get_version(VERSION)

default_app_config = 'django_extensions.apps.DjangoExtensionsConfig'
try:
import django

if django.VERSION < (3, 2):
default_app_config = 'django_extensions.apps.DjangoExtensionsConfig'
except ModuleNotFoundError:
# this part is useful for allow setup.py to be used for version checks
pass
2 changes: 1 addition & 1 deletion tests/management/commands/test_notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def test_without_args(capsys, settings):
call_command('notes')

out, err = capsys.readouterr()
assert 'tests/testapp/__init__.py:\n * [ 4] TODO this is a test todo\n\n' in out
assert 'tests/testapp/__init__.py:\n * [ 8] TODO this is a test todo\n\n' in out


def test_with_utf8(capsys, settings):
Expand Down
16 changes: 16 additions & 0 deletions tests/test_compatibility.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
"""Test Compatility between different django versions"""
import django
import pytest

import django_extensions


class TestDefaultAppConfigDefinition:
@pytest.mark.skipif(django.VERSION < (3, 2), reason='app config is automatically defined by django')
def test_app_config_not_defined(self):
assert hasattr(django_extensions, 'default_app_config') is False

@pytest.mark.skipif(django.VERSION >= (3, 2), reason='app config is not automatically defined by django')
def test_app_config_defined(self):
assert hasattr(django_extensions, 'default_app_config') is True
6 changes: 5 additions & 1 deletion tests/testapp/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# -*- coding: utf-8 -*-
default_app_config = 'tests.testapp.apps.TestAppConfig'
import django


if django.VERSION < (3, 2):
default_app_config = 'tests.testapp.apps.TestAppConfig'

# TODO: this is a test todo

0 comments on commit a85bcac

Please sign in to comment.