每当我尝试构建基于 self.live_server_url
的字符串时,我都会收到python TypeError
消息。例如,我尝试了以下字符串结构(下面的表单1和2),但我遇到了相同的TypeError
。我想要的字符串是附加了"/lists"
的Live Server URL。注意:实际测试确实成功创建了一个服务器,我可以手动访问服务器,更具体地说,我可以手动访问我尝试以编程方式构建的确切URL(例如'http://localhost:8081/lists
&#39 ;)
TypeError
。
# FORM 1
lists_live_server_url = '%s%s' % (self.live_server_url, '/lists')
# FORM 2
lists_live_server_url = '{0}{1}'.format(self.live_server_url, '/lists')
self.browser.get(lists_live_server_url)
这个表单没有python错误(没有附加到字符串中),虽然我的测试失败了(正如我所料,因为它不能访问/lists
)。
self.browser.get(self.live_server_url)
以下是我遇到的python错误。
/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/bin/python3.4 /Applications/PyCharm.app/Contents/helpers/pycharm/django_test_manage.py test functional_tests.lists_tests.LiveNewVisitorTest.test_can_start_a_list_and_retrieve_it_later /Users/myusername/PycharmProjects/mysite_proj
Testing started at 11:55 AM ...
Creating test database for alias 'default'...
Traceback (most recent call last):
File "/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/wsgiref/handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "/usr/local/lib/python3.4/site-packages/django/test/testcases.py", line 1104, in __call__
return super(FSFilesHandler, self).__call__(environ, start_response)
File "/usr/local/lib/python3.4/site-packages/django/core/handlers/wsgi.py", line 189, in __call__
response = self.get_response(request)
File "/usr/local/lib/python3.4/site-packages/django/test/testcases.py", line 1087, in get_response
return self.serve(request)
File "/usr/local/lib/python3.4/site-packages/django/test/testcases.py", line 1099, in serve
return serve(request, final_rel_path, document_root=self.get_base_dir())
File "/usr/local/lib/python3.4/site-packages/django/views/static.py", line 54, in serve
fullpath = os.path.join(document_root, newpath)
File "/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/posixpath.py", line 82, in join
path += b
TypeError: unsupported operand type(s) for +=: 'NoneType' and 'str'
我是否在不知不觉中尝试修改导致这些live_server_url
的{{1}}?我怎么能以编程方式构建一个TypeError
?
这是我正在尝试的测试...
live_server_url + "/lists"
答案 0 :(得分:3)
See this discussion on Reddit具有相同的错误Traceback
。
基本上,这不是Selenium
测试中的任何问题,而是项目的静态文件配置。
从您的问题来看,我认为Traceback
中的关键行是:
File "/usr/local/lib/python3.4/site-packages/django/views/static.py", line 54, in serve
fullpath = os.path.join(document_root, newpath)
此行表示在os.path.join
内尝试django.views.static
失败。
在项目的STATIC_ROOT
文件中设置settings.py
,您应该做得很好。
答案 1 :(得分:1)
使用StaticLiveServerTestCase可能会有帮助