Search code examples
python-3.xdjangotestingautomated-teststox

Django and Tox testing


I have a django package that I like to test against different versions of django using tox and with the python manage.py test command. On the newer versions, django has

from django.urls import reverse

available, but this doesnt exist on e.g. Django 1.8, because its in a diff path, but this version I am trying to test against, too.

Can someone point me to resources to find out how I can still make the tox testing pass? Whats the correct way of testing this? Is there some sort of conditional import I can do based on django version? Or maybe sth like

try:
    from django.urls import reverse
except ImportError:
    from django.core.urlresolvers import reverse

Im just not sure if this is the standard and safest way :)

Thanks!

tox config

[tox]
envlist =
    {py27,py35}-django18,
    {py27,py35}-django19,
    {py27,py35}-django110,
    {py27,py35,py36,py37}-django111,
    {py35,py36,py37}-django20,
    {py35,py36,py37}-django21,
    {py35,py36,py37}-django22,
    {py35,py36,py37,py38}-django30,
    {py38,py39,py310}-django40,

[testenv]
commands =
    python manage.py test

deps =
    django18: django==1.8.*
    django19: django==1.9.*
    django110: django==1.10.*
    django111: django==1.11.*
    django20: django==2.0.*
    django21: django==2.1.*
    django22: django==2.2.*
    django30: django>=3.0a1,<3.1
    django40: django==4.0.*

Solution

  • This is nothing which tox has to take care of, as tox is just driving the test runner, in your your case python manage.py test.

    You need to update your code and/or your tests to pass a python manage.py test for Django 1.8.