【发布时间】:2015-09-15 12:15:35
【问题描述】:
我想用 manage.py runserver 命令启动一个服务器,我正在尝试一段时间,但没有真正找到正确的方法。
from subprocess import Popen, PIPE
from django.test import TestCase
import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
class ExampleClass(TestCase):
def startServer(self):
process = Popen(['cd C:\mypath'], stdin=PIPE, stdout=PIPE)
process.stdin.write(['python', 'manage.py runserver'])
.
.
.
def test_examplename(self):
self.browser.get('http://localhost:8000')
每次我开始测试时,似乎该过程都在后台启动,但只要浏览器窗口弹出,它就会显示“无法连接”错误。 所以服务器没有运行。
请注意,当我自己启动服务器时,测试工作正常。
【问题讨论】:
标签: python django python-3.x testing