AttributeError'module'对象在django中没有属性'runserver' [英] AttributeError 'module' object has no attribute 'runserver' in django

查看:430
本文介绍了AttributeError'module'对象在django中没有属性'runserver'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个功能测试'y1.py',我试图从一个python / django函数调用。在调用函数里面我有:

  import unittest 
import ft1.y1
unittest.main = ft1.y1.py)

y1.py:


$ b来自selenium import webdriver
$ s code从selenium.webdriver.common.by导入
从selenium.webdriver.common.keys导入键
从selenium.webdriver.support.ui import从selenium.common.exceptions导入选择
导入NoSuchElementException
import unittest,time,re

class Y1(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url =https://www.yahoo。 com /
self.verificationErrors = []
self.accept_next_alert = True

def test_y1(self):
driver = self.driver
driver .get(self.base_url)
driver.find_element_by_link_text(Weather)。click()
driver.save_screenshot( 'out11.png')

def tearDown(self):
self.driver.quit()
self.assertEqual([],self.verificationErrors)

如果__name__ ==__main__:
unittest.main()


异常类型:/ runtest中的AttributeError /
异常值:'模块'对象没有属性'runserver'

我如何解决这个问题?



编辑:



我试过:

  unittest.main(module = ft1.y1,argv = [])

并得到: / p>

 追溯:
文件F:\envs\r1\lib\site-packages\django \core\handlers\base.pyin get_response
114. response = wrapped_callback(request,* callback_args,** callback_kwargs)
文件F:\envs\r1\driver1 \driver\views.py在runtest
31. unittest.main(module = ft1.y1,argv = [])
文件f:\ppython275\\ __init__
中的App \Lib\unittest\main.py93. self.progName = os.path.basename(argv [0])

异常类型:IndexError at / runtest /
异常值:列表索引超出范围

编辑2:



我很困惑它说测试OK,但是有一个错误:

 发生服务器错误。请联系管理员。 

验证模型

发现错误
2014年1月31日 - 14:42:50
Django版本1.6.1,使用设置'driver1.settings'
启动开发服务器http://127.0.0.1:8000/
使用CTRL-BREAK退出服务器。

---------------------------------------------- ------------------------
在6.286s中进行1次测试

OK
追溯(最多最近的电话最后):
文件f:\ppython275\App\Lib\wsgiref\handlers.py,第85行,运行
self.result = application(self.environ ,self.start_response)
文件F:\envs\r1\lib\site- packages\django\contrib\staticfiles\handlers.py,第67行,__call__
return self.application(environ,start_response)
文件F:\envs\r1\lib\site- packages\dj_static.py,第59行,__call__
返回self.application(environ,start_response)
文件F:\envs\r1\lib\site- packages\django\core\handlers\wsgi.py,第206行, __call__
response = self.get_response(request)
文件F:\envs\r1\lib\site- packages\django\core\handlers\base.py ,线114,g et_response
response = wrapped_callback(request,* callback_args,** callback_kwargs)
文件F:\envs\r1\driver1\driver\views.py,第32行,runtest
unittest.main(module = ft1.y1,argv = sys.argv [:1])$ ​​b $ b文件f:\ppython275\App\Lib\unittest\main.py ,第95行,__init__
self.runTests()
文件f:\ppython275\App\Lib\unittest\main.py,第234行在runTests
sys.exit(not self.result.wasSuccessful())
SystemExit:False
[31 / Jan / 2014 14:43:03]GET / runtest / HTTP / 1.1500 59


解决方案

您是否试图从视图中运行单位和硒?您应该考虑启动一个第二个进程。这样可以使您的django模块和测试模块之间更好的分离。如果你坚持使用unittest.main(),传递argv并退出params。

  import sys 
unittest。 main(module = ft.gtest,argv = sys.argv [:1],exit = False)

另请参见:





(已编辑)


I have a functional test 'y1.py' which I am trying to call from within a python/django function. Inside the calling function I have:

import unittest
import ft1.y1
unittest.main(module=ft1.y1.py)

y1.py:

   from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
import unittest, time, re    

class Y1(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Firefox()
        self.driver.implicitly_wait(30)
        self.base_url = "https://www.yahoo.com/"
        self.verificationErrors = []
        self.accept_next_alert = True

    def test_y1(self):
        driver = self.driver
        driver.get(self.base_url)
        driver.find_element_by_link_text("Weather").click()
        driver.save_screenshot('out11.png')    

    def tearDown(self):
        self.driver.quit()
        self.assertEqual([], self.verificationErrors)    

if __name__ == "__main__":
    unittest.main()


Exception Type: AttributeError at /runtest/
Exception Value: 'module' object has no attribute 'runserver'

How can I fix this?

edit:

I tried:

unittest.main(module=ft1.y1, argv=[])

and got:

Traceback:
File "F:\envs\r1\lib\site-packages\django\core\handlers\base.py" in get_response
  114.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "F:\envs\r1\driver1\driver\views.py" in runtest
  31.     unittest.main(module=ft1.y1, argv=[])
File "f:\ppython275\App\Lib\unittest\main.py" in __init__
  93.         self.progName = os.path.basename(argv[0])    

Exception Type: IndexError at /runtest/
Exception Value: list index out of range

edit 2:

I'm confused it says test OK , but there is an error:

A server error occurred.  Please contact the administrator.    

Validating models...    

0 errors found
January 31, 2014 - 14:42:50
Django version 1.6.1, using settings 'driver1.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
.
----------------------------------------------------------------------
Ran 1 test in 6.286s    

OK
Traceback (most recent call last):
  File "f:\ppython275\App\Lib\wsgiref\handlers.py", line 85, in run
    self.result = application(self.environ, self.start_response)
  File "F:\envs\r1\lib\site-packages\django\contrib\staticfiles\handlers.py", line 67, in __call__
    return self.application(environ, start_response)
  File "F:\envs\r1\lib\site-packages\dj_static.py", line 59, in __call__
    return self.application(environ, start_response)
  File "F:\envs\r1\lib\site-packages\django\core\handlers\wsgi.py", line 206, in __call__
    response = self.get_response(request)
  File "F:\envs\r1\lib\site-packages\django\core\handlers\base.py", line 114, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "F:\envs\r1\driver1\driver\views.py", line 32, in runtest
    unittest.main(module=ft1.y1, argv=sys.argv[:1])
  File "f:\ppython275\App\Lib\unittest\main.py", line 95, in __init__
    self.runTests()
  File "f:\ppython275\App\Lib\unittest\main.py", line 234, in runTests
    sys.exit(not self.result.wasSuccessful())
SystemExit: False
[31/Jan/2014 14:43:03] "GET /runtest/ HTTP/1.1" 500 59    

解决方案

Are you trying to run unitest and selenium from a view? You should consider launching a second process for that. This gives you better separation between your django modules and tested modules. If you insist on using unittest.main(), pass the argv and exit params.

import sys
unittest.main(module=ft.gtest, argv=sys.argv[:1], exit=False)

See also:

(Edited)

这篇关于AttributeError'module'对象在django中没有属性'runserver'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆