问题描述
我目前正在使用行为进行测试,一切都按预期工作,但是当我尝试连接到 websocket 时,我似乎无法连接并返回 404。我已阅读 [https://github.com] /behave/behave-django/issues/16][1] 我必须设置一个通道后端。我尝试使用通道 ChannelLiveServerTestCase 而不是 StaticLiveServerTestCase 但我得到的只是连接被拒绝作为错误。我不确定我是否做得对,因为我只是行为和渠道方面的新手。
下面是我的environment.py
import os
import django
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from channels.testing import ChannelsLiveServerTestCase
from django.shortcuts import resolve_url
from django.test.runner import discoverRunner
os.environ["DJANGO_SETTINGS_MODULE"] = "app.settings_test"
django.setup()
def before_all(context):
context.test_runner = discoverRunner()
context.test_runner.setup_test_environment()
context.old_db_config = context.test_runner.setup_databases()
context.test = BehaviorDrivenTestCase()
context.test.setUpClass()
# This starts a transaction
context.test()
context.base_url = context.test.live_server_url
class BehaviorDrivenTestCase(ChannelsLiveServerTestCase):
serve_static = True
"""
Test case attached to the context during behave execution
This test case prevents the regular tests from running.
"""
def runTest(*args,**kwargs):
pass
def test(self):
self.live_server_url
def after_all(context):
context.test.tearDownClass()
del context.test
context.test_runner.teardown_databases(context.old_db_config)
context.test_runner.teardown_test_environment()
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)