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.


django_test_runner_py_-_django-upharm_-____PycharmProjects_django-upharm_.png
0
10 comments
Avatar
Permanently deleted user
I have the same issues. The tests work in some cases, but not in all. Of course the ones they don't work in are the ones I need too!
0
Avatar
Permanently deleted user
I ended up doing a rough hack of the PyCharm helper script so 1.7 testing works again. I can share diffs if it might be useful.
0
Yes I'd like to see some diffs to workaround this until there is an official response from Jetbrains.
0
Avatar
Permanently deleted user
Was there a solution to this problem?
0
Avatar
Permanently deleted user
No solution, just a workaround.

**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.
0
Avatar
Permanently deleted user
All right, these are the files that I've had to tweak.

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.
0
Avatar
Permanently deleted user
Additionally, if you use Sphinx to produce documentation, you'll need to activate Django in the helper:

/Applications/PyCharm.app/helpers/rest_runners/sphinx_runner.py
3,5d2
< import django
< django.setup()
<
0
Avatar
Permanently deleted user
When I run my tests in a python script it modifies my production database. If I run from the command line it doesn't. When I say modify, it wipes out my existing users and replaces them with the users I create for testing.
0
Avatar
Permanently deleted user
Ripelnet, personally that seems serious enough for its own discussion thread to get some attention. It appears that there are two bugs in youtrack to take care of the issue in this thread.
0

Please sign in to leave a comment.