My app is called abcapp. I am running Django 1.5b1 on Python 2.7. The same issue happens in the latest trunk release of django.
我的应用程序叫做abcapp。我在Python 2.7上运行Django 1.5b1。同样的问题发生在django的最新trunk版本中。
When I run manage.py test abcapp
all tests which I have written pass.
当我运行manage.py test abcapp时,我写的所有测试都通过了。
When I run manage.py test
I get a cascade of failures. The first of these failures is shown:
当我运行manage.py测试时,我遇到了一连串的失败。显示了第一个失败:
Traceback (most recent call last):
File "C:\Program Files\Django-1.5b1\django\core\handlers\base.py", line 116, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "C:\Program Files\Django-1.5b1\django\views\decorators\cache.py", line 89, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "C:\Program Files\Django-1.5b1\django\contrib\messages\tests\urls.py", line 30, in add
getattr(messages, message_type)(request, msg)
File "C:\Program Files\Django-1.5b1\django\contrib\messages\api.py", line 70, in debug
fail_silently=fail_silently)
File "C:\Program Files\Django-1.5b1\django\contrib\messages\api.py", line 22, in add_message
raise MessageFailure('You cannot add messages without installing '
MessageFailure: You cannot add messages without installing django.contrib.messages.middleware.MessageMiddleware
The test results are:
测试结果如下:
======================================================================
FAIL: test_clearsessions_command (django.contrib.sessions.tests.FileSessionTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Program Files\Django-1.5b1\django\test\utils.py", line 213, in inner
return test_func(*args, **kwargs)
File "C:\Program Files\Django-1.5b1\django\contrib\sessions\tests.py", line 444, in test_clearsessions_command
self.assertEqual(1, count_sessions())
AssertionError: 1 != 2
----------------------------------------------------------------------
Ran 474 tests in 5.768s
FAILED (failures=1, skipped=141, expected failures=1)
Contrary to the messages, I do have django.contrib.messages.middleware.MessageMiddleware
in my MIDDLEWARE_CLASSES
. The value of my MIDDLEWARE_CLASSES
is below. I use messages within my app without any issues.
与消息相反,我的MIDDLEWARE_CLASSES中有django.contrib.messages.middleware.MessageMiddleware。我的MIDDLEWARE_CLASSES的值如下。我在我的应用程序中使用消息没有任何问题。
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware',
)
Can anyone shed some light on this issue? While I can run my own tests only, I would like to run the entire suite to ensure proper quality control.
任何人都可以对这个问题有所了解吗?虽然我只能运行自己的测试,但我想运行整个套件以确保适当的质量控制。
Research results: I noticed through my own testing, that when the test http Client is used, none of the middleware is loaded. I discovered this when I was trying to test my own middleware through web requests in the test Client. If that is the case, would this mean that there is untestable code in the djanog core?
研究结果:我通过自己的测试注意到,当使用测试http客户端时,没有加载任何中间件。当我试图通过测试客户端中的Web请求测试我自己的中间件时,我发现了这一点。如果是这种情况,这是否意味着djanog核心中存在不可测试的代码?
1 个解决方案
#1
8
It seems that is a bug of the windows version.
这似乎是Windows版本的一个错误。
Here is the issue File-based session does not store any data on Windows. Recommended workaround: just replace os.rename
with shutil.move
in django/contrib/sessions/backends/file.py
:
以下是基于文件的会话不在Windows上存储任何数据的问题。建议的解决方法:在django / contrib / sessions / backends / file.py中用shutil.move替换os.rename:
+import shutil
....
-os.rename(output_file_name, session_file_name)
+shutil.move(output_file_name, session_file_name)
#1
8
It seems that is a bug of the windows version.
这似乎是Windows版本的一个错误。
Here is the issue File-based session does not store any data on Windows. Recommended workaround: just replace os.rename
with shutil.move
in django/contrib/sessions/backends/file.py
:
以下是基于文件的会话不在Windows上存储任何数据的问题。建议的解决方法:在django / contrib / sessions / backends / file.py中用shutil.move替换os.rename:
+import shutil
....
-os.rename(output_file_name, session_file_name)
+shutil.move(output_file_name, session_file_name)