为什么 Django Websockets 的测试必须用 pytest 编写?
Why do tests for Django Websockets have to be written in pytest?
所有教程和官方文档都指向使用pytest 来测试Django 的websockets。我的问题是为什么 Django 的 unittest 框架不能直接使用,什么时候可以改变?
unittest 是标准 python 模块,与 Django 没有直接关系,因为它只使用它。
您可以使用 unittest 测试异步函数,但样板文件要多得多(import asyncio 等)
作为频道状态的文档
If you have normal Django views, you can continue to test those with
the standard Django test tools and client. You only need the async
setup for code that’s written as consumers.
这是频道使用 pytest-asyncio 的原因,以后不会改变
所有教程和官方文档都指向使用pytest 来测试Django 的websockets。我的问题是为什么 Django 的 unittest 框架不能直接使用,什么时候可以改变?
unittest 是标准 python 模块,与 Django 没有直接关系,因为它只使用它。
您可以使用 unittest 测试异步函数,但样板文件要多得多(import asyncio 等)
作为频道状态的文档
If you have normal Django views, you can continue to test those with the standard Django test tools and client. You only need the async setup for code that’s written as consumers.
这是频道使用 pytest-asyncio 的原因,以后不会改变