Uprade Django 1.6.5 to 1.7 - tests not working now
I took the plunge to upgrade the virtual environment for our project from Django 1.6.5 to Django 1.7.
When I use the menu to run Tools | Run manage.py Task then select "test" the tests don't run, with the message:
/Users/jamesk/upharm27/lib/python2.7/site-packages/django/test/_doctest.py:62: RemovedInDjango18Warning: The django.test._doctest module is deprecated; use the doctest module from the Python standard library instead.
RemovedInDjango18Warning)
To figure out what was causing this, I put the following lines in django.test._doctest, immediately before the warning command:
import traceback
traceback.print_stack()
It shows (in part) the following:
File "/Applications/PyCharm.app/helpers/pycharm/django_test_runner.py", line 30, in <module>
from django.test.simple import DjangoTestSuiteRunner
File "/Users/jamesk/upharm27/lib/python2.7/site-packages/django/test/simple.py", line 13, in <module>
from django.test import _doctest as doctest
File "/Users/jamesk/upharm27/lib/python2.7/site-packages/django/test/_doctest.py", line 57, in <module>
traceback.print_stack()
/
Which I interpret as PyCharm's django_test_runner.py imporint django.test.simple, which triggers the deprecation warning.
What would be recommended here? It would appear to my untrained eyes that PyCharm's helper script is out of date for Django 1.7, but I'm not entirely sure.
Thank you!
OS: OS X 10.9.4
Pycharm: 3.4.1
Python: 2.7.6 in virtual environment.
When I use the menu to run Tools | Run manage.py Task then select "test" the tests don't run, with the message:
/Users/jamesk/upharm27/lib/python2.7/site-packages/django/test/_doctest.py:62: RemovedInDjango18Warning: The django.test._doctest module is deprecated; use the doctest module from the Python standard library instead.
RemovedInDjango18Warning)
To figure out what was causing this, I put the following lines in django.test._doctest, immediately before the warning command:
import traceback
traceback.print_stack()
It shows (in part) the following:
File "/Applications/PyCharm.app/helpers/pycharm/django_test_runner.py", line 30, in <module>
from django.test.simple import DjangoTestSuiteRunner
File "/Users/jamesk/upharm27/lib/python2.7/site-packages/django/test/simple.py", line 13, in <module>
from django.test import _doctest as doctest
File "/Users/jamesk/upharm27/lib/python2.7/site-packages/django/test/_doctest.py", line 57, in <module>
traceback.print_stack()
/
Which I interpret as PyCharm's django_test_runner.py imporint django.test.simple, which triggers the deprecation warning.
What would be recommended here? It would appear to my untrained eyes that PyCharm's helper script is out of date for Django 1.7, but I'm not entirely sure.
Thank you!
OS: OS X 10.9.4
Pycharm: 3.4.1
Python: 2.7.6 in virtual environment.
Please sign in to leave a comment.
**facepalm** Like an idiot I didn't do a copy before I edited the helper so I can't do the diff as I had thought I would.
I can jog things around to get the diffs against a fresh install of PyCharm, but I'm not in a position where I can do it at this moment.
The following allows the Django shell within PyCharm to have Django loaded.
/Applications/PyCharm.app/helpers/pycharm/django_manage_shell.py
6a7,9
> import django
> django.setup()
>
This is an incomplete attempt to patch the Django test runner so it'll still work with older Django versions, but I never got back to it.
However it works fine with Django 1.7 and I'm able to run unit tests.
The important point is that django.tests.testcases should not be used. Rather, the standard Python unittest.TestCase should be used.
/Applications/PyCharm.app/helpers/pycharm/django_test_runner.py
13c13
< from django.test.testcases import TestCase
---
> from unittest import TestCase
15,18c15,21
< try:
< from django.utils import unittest
< except ImportError:
< import unittest
---
> if VERSION[0] > 1 or VERSION[0] == 1 and VERSION[1] >= 8:
> import unittest
> else:
> try:
> from django.utils import unittest
> except ImportError:
> import unittest
30c33
< from django.test.simple import DjangoTestSuiteRunner
---
> from django.test.runner import DiscoverRunner
41c44
< BaseSuiteRunner = SUITE_RUNNER or DjangoTestSuiteRunner
---
> BaseSuiteRunner = SUITE_RUNNER or DiscoverRunner
I hope this is helpful.
/Applications/PyCharm.app/helpers/rest_runners/sphinx_runner.py
3,5d2
< import django
< django.setup()
<