使用测试异步库的功能增强标准unittest包

asynctest的Python项目详细描述


PyPITravisAppVeyorSupported Python versions

异步测试

包asynctest构建在标准unittest模块之上,并且 在测试异步库时减少样板代码。

目前,AsyncTest的目标是“选择器”模型,因此,有些特性 不会吧?使用windows的代理。

警告

由于AsyncTest0.13,因此不再支持Python3.4。

作者和许可证

作者:Martin Richard,martius@martiusweb.net>;并根据 Apache2许可证。

有关作者的完整列表,请参见作者文件。

文件

https://readthedocs.org/projects/asynctest/badge/

完整的文档可在http://asynctest.readthedocs.org/en/latest/获得。 它包括一个教程,其中包含了如何使用TestCase或 嘲笑。

功能

测试用例
  • Initialize and close a loop created for each test (it can be configurated), if the loop uses a selector, it will be updated with a TestSelector object wrapping the original selector (see below),
  • if the test function is a coroutine function or returns a coroutine, it will run on the loop,
  • TestCase.setUp() and TestCase.tearDown() can be coroutine functions,
  • control post-test checks with @fail_on, for instance, the test fail if the loop didn’t run, some optional checks can be activated,
  • ClockedTestCase allows to control the loop clock and run timed events without waiting the wall clock.

模拟和协同工作
  • CoroutineMock is a new Mock class which mocks a coroutine function, and returns a coroutine when called,
  • MagicMock supports asynchronous context managers and asynchronous iterators,
  • NonCallableMock, Mock and CoroutineMock can return CoroutineMock objects when its attributes are get if there is a matching attribute in the spec (or spec_set) object which is a coroutine function,
  • patch(), patch.object(), patch.multiple() return a MagickMock or CoroutineMock object by default, according to the patched target,
  • patch(), patch.object(), patch.multiple() handle generators and coroutines and their behavior can be controled when the generator or coroutine pauses,
  • all the patch() methods can decorate coroutine functions,
  • mock_open() returns a MagickMock object by default.
  • return_once() can be used with Mock.side_effect to return a value only once when a mock is called.

选择器

模块asynctest.selector提供类来模拟执行IO的对象 (文件、套接字等)。

  • FileMock is a special type of mock which represents a file. FileMock.fileno() returns a special value which allows to identify uniquely the mock,
  • SocketMock is a special type of FileMock which uses socket.socket as spec,
  • TestSelector is a custom selector able to wrap a real selector implementation and deal with FileMock objects, it can replace a selector loop by calling loop._selector = TestSelector(loop._selector), and will intercept mock so they don’t get registered to the actual selector.
  • set_read_ready() and set_write_ready() to force read and write event callbacks to be scheduled on the loop, as if the selector scheduled them.

助手

  • the coroutine exhaust_callbacks(loop) returns once all the callbacks which should be called immediately are executed, which is useful when the test author needs to assert things which are not yet executed by the loop.

路线图

我希望有时间开发和发布以下功能:

  • 对常见错误的一组警告
  • 演员支持

测试

AsyncTest是单元测试。您可以使用以下命令运行AsyncTest测试套件:

$ PYTHONPATH=. python -m unittest test

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
插入表达式以完成JAVA语句块时出现语法错误   在linkedlist中的特定节点后插入java   java如何将参数传递给安卓 junit测试(参数化测试)   java在运行时将数据添加到片段中的RecyclerView,在该片段中,数据是在单独的片段中创建的   java apache CsrfPreventionFilter和404错误   java Ask是安卓 6.0的多重权限   java将字符串解析为Time并插入mysqldatabase   java扩展MyBatis映射器接口可能导致异常   java SparkSql不支持日期格式   在java中剪切字符串的一部分   将Java lambda的结果分配给字段   在Java中解析OCL?   java解析json到安卓中活动中的对象   用于时区转换的JavaAPI   在Oracle上建立与ESRI geodatabase直接连接的java在未处于调试模式时挂起   拆分文件时出错。使用Java8的xml文件   java eclipse jsp无颜色、代码完成和错误检测   java spring kafka侦听器在错误的位置查找ContainerProperty   java Springboot应用程序@EnableConfigServer无法在Eclipse中解析   当尝试使用ConstraintLayout将java视图添加到同一行时,java视图会被截断