用于编排测试的pytest插件

pytest-orchestration的Python项目详细描述


Pytest业务流程

pytest业务流程是配置驱动的测试业务流程插件,旨在用于性能测试,但它也可能适合其他用途。

安装

pip install pytest-orchestration

配置/说明

描述编排测试的配置的格式为.json文件。 这些文件所在的位置在pytest.ini的“业务流程描述”下定义。注意,文件名也应该与文件中的test_name键匹配

[pytest]
orchestration_descriptions = orchestration/descriptions/

下面是一个带有注释的配置示例:

{
  "test_name": "my_orchestration_test",                 // Name of the test (no need to have a "test" prefix or suffix)
  "total_hours": 3,                                     // Total number of hours for the test to run
  "unref_setup_fixtures": ["device_with_collectd"],     // A list of setup fixtures that won't be references in actual test events
  "events": [                                           // A list of all "events" making up the test
    {
      "name": "start_playback",                         // Mandatory: The name of the event as it is implemented, see Events section below
      "interval_sec": 300,                              // Optional: The number of seconds between eache execution of this event. If it is not set, then the event will only be triggerd according to "at_startup" and "at_teardown"
      "at_startup": true,                               // Optional(Defaults to true): Specifies if the event should be executed once on startup, if false it will wait interval_sec befor being executed.
      "at_teardown": false,                              // Optional(Defaults to false): Specifies if a event should be executed on teardown, one last time after the time "total_hours" have been reached.
      "params":{                                        // Optional: Params is a dict of simple key: values that would be used in the implemented events
        "video_path": "/home/orch-tests/video-files/high_res_clip.mp4"
      }
    },
    {
      "name": "start_streamer",
      "at_startup": true
    },
    {
      "name": "collect_system_report",
      "at_startup": false,
      "at_teardown": true
    }
  ]
}

事件

事件构成了编排的测试。从上面的配置示例中,我们有3个事件;start_playbackstart_streamercollect_system_report。每个事件都需要有相应的功能这些函数在pytest.ini中的orchestration_sources下指定,可以是逗号(',')分隔的文件列表。

[pytest]
orchestration_sources = tests/event_plugin.py, somethingelse.py

这些事件实现可以使用任何现有的PyTestEngt作为参数,也可以使用配置/描述中定义的任何参数,参见上面配置示例中的“VIETOOPYPATH”。

请参阅上面配置示例中start_playback的实际事件实现。 它的输入参数是:

  • “视频播放器”-我们已经在我们的事件中使用的设备
  • “视频路径”-配置/描述文件中定义的输入
  • “kill_switch”-提供的kill_switch fixture,我们将其发送给您play method,因为它将启动一个子进程,而编排不能自行停止,因此通过kill_switch,我们向它发送信号,它必须自行停止
  • “result_reporter”-我们传入result_reporter,以便play方法可以添加其信息/错误,无论该编排是什么,然后当有新的报告时,将监视并在_result()上执行
def start_playback(video_player, video_path, kill_switch, result_reporter):
    video_player.play(video_path, kill_switch, result_reporter)

记者

Reporter是一个类,前提是业务流程用于从其所有编排的事件收集报告/结果/信息实现的事件可以使用result_reporter()fixture来获取实例。报告者有两个主要方法值得注意;monitor()on_result()。monitor方法将在orchestration的后台运行,并监视它包含的队列对象以获取新信息,如果它找到了某些内容,则将调用on_result(),这将弹出该信息并将其记录下来。通过继承提供的resultreporter类并实现自己的on_result()方法,可以实现自己的reporter类。如果您实现了这一点,还需要重写result_reporter(report_queue)fixture并使其返回您的报告器

固定装置

插件附带了几个fixture助手,它们是:

  • kill_switch()-为您提供一个multiprocessing.Event(),它将在测试完成时设置,这样您的事件就可以知道测试何时结束,并正确地自行终止。
  • result_reporter()-有助于收集和报告事件中的重要内容,请参阅报告部分。
  • report-queue()-fixture返回一个线程安全的multiprocessing.Manager().Queue()对象,该对象被注入result-reporter,也可以被重写。

用法

要运行业务流程测试,只需指定--run orch=<;orch\u name>;其中orch\u name应该是描述配置文件的名称,不包括其扩展名。

pytest --test-orch=my_orchestration_test

选项--load-orch也可用,指定此选项将加载所有事件。这主要是为了测试

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

推荐PyPI第三方库


热门话题
如何在Java和Javascript之间共享常量   c#无法使用Gson反序列化字节[]   如果字符串是实十进制数字,则在Java中仅显示十进制数字   与Android Studio的java FireBase同步失败   web应用程序的Java Oracle数据库更改通知问题   数组中缺少整数的java嵌套循环   zos在z/os上以TOD格式(一天中的时间)转换Java时间戳   java JAXB未根据注释生成XML(JDK 1.7)   java使用Twitter4j和Geolocation查找在该地区发布推文的用户,但如何获取用户ID?   在Libgdx中实现简单运动模糊的java意外结果   java在Android数据库中插入另一个EditText值?   java标准偏差数组(我的算法错误)   java如何修复M1 Mac的Ant javascript标记?   java遍历树标记值的长度   java理解Springboot中的Cron,自动发送电子邮件   java如何将“Data.Json”文件从资产保存到内部存储器,然后将其用于读/写   java代码在编写FirstDuplicate方法时会遇到时间限制问题   java将HTML转换为PDF并将其添加到段落中   javascript css()未设置正文标记的背景属性