如何解决在 websocket 测试中表现失败
我目前正在使用行为进行测试,一切都按预期工作,但是当我尝试连接到 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 举报,一经查实,本站将立刻删除。