我正在使用* django_webtest *来测试我的视图和* django_nose_selenium *来测试我网站上的ajax(我无法获得webtest.sel工作+静态文件,因为在运行单元测试时debug = False)。< / p>
我正在使用完整的测试套件
./manage.py test project --with-selenium --with-cherrypyliveserver
并且在django_webtest和硒测试之间不断变得不稳定。
似乎当我有一个奇数数量的django webtest时,套件通过 - 当它是偶数数字时,我得到的SAVEPOINT只能用于事务块异常(见堆栈下面)。我发现通过添加一个简单的测试用例(assertTrue(2 == 1 + 1)。
这可能与cherrypy服务器设置有关吗?有关可能发生的事情的任何想法? 您使用哪些工具组合来测试您的观点+ ajax?
======================================================================
ERROR: test_update_project_files (proj.apps.project.tests.UpdateProjectTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/kepioo/Documents/code/virtualenvs/myproject/proj/../proj/apps/project/tests/integration_tests.py", line 88, in test_update_project_files
response = self.app.get("/project/manage/sample-project-name/", user="username")
File "/Users/kepioo/Documents/code/virtualenvs/myproject/lib/python2.6/site-packages/django_webtest/__init__.py", line 71, in get
url, params, headers, extra_environ, status, expect_errors)
File "/Users/kepioo/Documents/code/virtualenvs/myproject/lib/python2.6/site-packages/webtest/app.py", line 756, in get
expect_errors=expect_errors)
File "/Users/kepioo/Documents/code/virtualenvs/myproject/lib/python2.6/site-packages/django_webtest/__init__.py", line 42, in do_request
response = super(DjangoTestApp, self).do_request(req, status, expect_errors)
File "/Users/kepioo/Documents/code/virtualenvs/myproject/lib/python2.6/site-packages/webtest/app.py", line 1000, in do_request
res = req.get_response(app, catch_exc_info=True)
File "/Users/kepioo/Documents/code/virtualenvs/myproject/lib/python2.6/site-packages/webob/request.py", line 1145, in get_response
application, catch_exc_info=True)
File "/Users/kepioo/Documents/code/virtualenvs/myproject/lib/python2.6/site-packages/webob/request.py", line 1118, in call_application
app_iter = application(self.environ, start_response)
File "/Users/kepioo/Documents/code/virtualenvs/myproject/lib/python2.6/site-packages/webtest/lint.py", line 173, in lint_app
iterator = application(environ, start_response_wrapper)
File "/Users/kepioo/Documents/code/virtualenvs/myproject/lib/python2.6/site-packages/django_webtest/middleware.py", line 77, in __call__
return self.app(environ, start_response)
File "/Users/kepioo/Documents/code/virtualenvs/myproject/lib/python2.6/site-packages/django/contrib/staticfiles/handlers.py", line 68, in __call__
return self.application(environ, start_response)
File "/Users/kepioo/Documents/code/virtualenvs/myproject/lib/python2.6/site-packages/django/core/handlers/wsgi.py", line 272, in __call__
response = self.get_response(request)
File "/Users/kepioo/Documents/code/virtualenvs/myproject/lib/python2.6/site-packages/django/core/handlers/base.py", line 169, in get_response
response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
File "/Users/kepioo/Documents/code/virtualenvs/myproject/lib/python2.6/site-packages/django/core/handlers/base.py", line 89, in get_response
response = middleware_method(request)
File "/Users/kepioo/Documents/code/virtualenvs/myproject/lib/python2.6/site-packages/django_webtest/middleware.py", line 49, in process_request
auth.login(request, user)
File "/Users/kepioo/Documents/code/virtualenvs/myproject/lib/python2.6/site-packages/django/contrib/auth/__init__.py", line 80, in login
request.session.cycle_key()
File "/Users/kepioo/Documents/code/virtualenvs/myproject/lib/python2.6/site-packages/django/contrib/sessions/backends/base.py", line 271, in cycle_key
self.create()
File "/Users/kepioo/Documents/code/virtualenvs/myproject/lib/python2.6/site-packages/django/contrib/sessions/backends/db.py", line 40, in create
self.save(must_create=True)
File "/Users/kepioo/Documents/code/virtualenvs/myproject/lib/python2.6/site-packages/django/contrib/sessions/backends/db.py", line 61, in save
sid = transaction.savepoint(using=using)
File "/Users/kepioo/Documents/code/virtualenvs/myproject/lib/python2.6/site-packages/django/db/transaction.py", line 162, in savepoint
return connection.savepoint()
File "/Users/kepioo/Documents/code/virtualenvs/myproject/lib/python2.6/site-packages/django/db/backends/__init__.py", line 223, in savepoint
self._savepoint(sid)
File "/Users/kepioo/Documents/code/virtualenvs/myproject/lib/python2.6/site-packages/django/db/backends/__init__.py", line 70, in _savepoint
self.cursor().execute(self.ops.savepoint_create_sql(sid))
File "/Users/kepioo/Documents/code/virtualenvs/myproject/lib/python2.6/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 44, in execute
return self.cursor.execute(query, args)
DatabaseError: SAVEPOINT can only be used in transaction blocks
-------------------- >> begin captured stdout << ---------------------
query exception SAVEPOINT s140735086238912_x1
--------------------- >> end captured stdout << ----------------------
-------------------- >> begin captured logging << --------------------
tracking.middleware: DEBUG: Created a new visitor: {'session_key': '8a0c9599b9fcf95d75fc01ad3ed4411e', 'ip_address': '127.0.0.1'}
--------------------- >> end captured logging << ---------------------
----------------------------------------------------------------------
Ran 3 tests in 28.389s
FAILED (errors=1)
Destroying test database for alias 'default' ('test_mydb')...
答案 0 :(得分:2)
我正在使用webtest.sel而没有问题。如果您正在进行测试,只需添加一些内容来提供静态文件
让我们说一个env var:
TEST=True ./manage.py test project
然后在你的urls.py中:
if settings.DEBUG or 'TEST' in os.environ:
# serve static files