为什么pytest数据驱动多采用yaml,而不采用excel

为什么pytest数据驱动多采用yaml,而不采用excel?

用excel主要有如下几个缺点

版本化管理

excel是二进制文件,如果有人修改了一行数据,那么你无法通过git diff知道它的修改范围,这是很可怕的。修改无法便捷的review,除非你开发特定的对比工具,或者多做一些对比工作

树形结构数据处理

excel是行列二维数据,多个sheet本质也是一个列表数据。对于嵌套型数据结构,不能很方便的维护和表示。你应该听说过各种序列化、比如二进制序列化,或者json序列化,很少会听说excel csv序列化,因为excel和csv二维数据类型,不是完备的数据类型。对应的json xml yaml其实都是完备的数据类型。

{
  "post_stream": {
    "posts": [
      {
        "id": 52908,
        "name": "conneyma",
        "username": "conneyma",
        "avatar_template": "/letter_avatar_proxy/v4/letter/c/a88e4f/{size}.png",
        "created_at": "2022-06-02T05:34:06.222Z",
        "cooked": "<p>为什么pytest数据驱动多采用yaml,而不采用excel?</p>",
        "post_number": 1,
        "post_type": 1,
        "updated_at": "2022-06-02T05:34:06.222Z",
        "reply_count": 0,
        "reply_to_post_number": null,
        "quote_count": 0,
        "incoming_link_count": 1,
        "reads": 7,
        "readers_count": 6,
        "score": 6.4,
        "yours": false,
        "topic_id": 21103,
        "topic_slug": "topic",
        "display_username": "conneyma",
        "primary_group_name": null,
        "flair_name": null,
        "flair_url": null,
        "flair_bg_color": null,
        "flair_color": null,
        "version": 1,
        "can_edit": false,
        "can_delete": false,
        "can_recover": false,
        "can_wiki": false,
        "read": true,
        "user_title": null,
        "bookmarked": false,
        "actions_summary": [],
        "moderator": false,
        "admin": false,
        "staff": false,
        "user_id": 3962,
        "hidden": false,
        "trust_level": 0,
        "deleted_at": null,
        "user_deleted": false,
        "edit_reason": null,
        "can_view_edit_history": true,
        "wiki": false,
        "can_accept_answer": false,
        "can_unaccept_answer": false,
        "accepted_answer": false,
        "can_translate": false
      }
    ],
    "stream": [
      52908
    ]
  },
  "timeline_lookup": [
    [
      1,
      0
    ]
  ],
  "suggested_topics": [
    {
      "id": 13277,
      "title": "Linux服务器搭建mysql",
      "fancy_title": "Linux服务器搭建mysql",
      "slug": "topic",
      "posts_count": 7,
      "reply_count": 5,
      "highest_post_number": 8,
      "image_url": null,
      "created_at": "2021-06-29T12:16:34.325Z",
      "last_posted_at": "2021-08-18T01:31:52.926Z",
      "bumped": true,
      "bumped_at": "2021-08-18T01:31:52.926Z",
      "archetype": "regular",
      "unseen": false,
      "pinned": false,
      "unpinned": null,
      "visible": true,
      "closed": false,
      "archived": false,
      "bookmarked": null,
      "liked": null,
      "tags": [
        "done"
      ],
      "tags_descriptions": {},
      "like_count": 0,
      "views": 559,
      "category_id": 73,
      "featured_link": null,
      "has_accepted_answer": false,
      "posters": [
        {
          "extras": null,
          "description": "原始发帖人",
          "user": {
            "id": 3840,
            "username": "302799464",
            "name": "小太阳",
            "avatar_template": "/letter_avatar_proxy/v4/letter/3/71e660/{size}.png"
          }
        },
        {
          "extras": "latest",
          "description": "最新发帖人",
          "user": {
            "id": 232,
            "username": "xiaoxi",
            "name": "测开17期学委-晓兮",
            "avatar_template": "/user_avatar/ceshiren.com/xiaoxi/{size}/13863_2.png"
          }
        }
      ]
    },
    {
      "id": 15797,
      "title": "使用jenkins运行pycharm本地上传升级包操作时无法点击被本地目录窗口",
      "fancy_title": "使用jenkins运行pycharm本地上传升级包操作时无法点击被本地目录窗口",
      "slug": "topic",
      "posts_count": 2,
      "reply_count": 0,
      "highest_post_number": 2,
      "image_url": "https://ceshiren.com/uploads/default/optimized/3X/b/0/b05d68b7fa11cad2a2ce69d2d10ebe724fc60553_2_1024x532.png",
      "created_at": "2021-12-13T09:01:21.991Z",
      "last_posted_at": "2021-12-13T17:53:08.612Z",
      "bumped": true,
      "bumped_at": "2021-12-13T17:53:08.612Z",
      "archetype": "regular",
      "unseen": false,
      "pinned": false,
      "unpinned": null,
      "visible": true,
      "closed": false,
      "archived": false,
      "bookmarked": null,
      "liked": null,
      "tags": [
        "python"
      ],
      "tags_descriptions": {},
      "like_count": 0,
      "views": 178,
      "category_id": 73,
      "featured_link": null,
      "has_accepted_answer": false,
      "posters": [
        {
          "extras": null,
          "description": "原始发帖人",
          "user": {
            "id": 5205,
            "username": "sunflower",
            "name": "sunflower",
            "avatar_template": "/letter_avatar_proxy/v4/letter/s/a5b964/{size}.png"
          }
        },
        {
          "extras": "latest",
          "description": "最新发帖人",
          "user": {
            "id": 1,
            "username": "seveniruby",
            "name": "思寒",
            "avatar_template": "/user_avatar/ceshiren.com/seveniruby/{size}/2_2.png"
          }
        }
      ]
    },
    {
      "id": 14841,
      "title": "pytest 使用多线程可以和Allure报告结合吗?",
      "fancy_title": "pytest 使用多线程可以和Allure报告结合吗?",
      "slug": "topic",
      "posts_count": 2,
      "reply_count": 0,
      "highest_post_number": 2,
      "image_url": null,
      "created_at": "2021-11-05T11:16:30.369Z",
      "last_posted_at": "2021-11-05T14:08:41.929Z",
      "bumped": true,
      "bumped_at": "2021-11-05T14:08:41.929Z",
      "archetype": "regular",
      "unseen": false,
      "pinned": false,
      "unpinned": null,
      "visible": true,
      "closed": false,
      "archived": false,
      "bookmarked": null,
      "liked": null,
      "tags": [
        "python"
      ],
      "tags_descriptions": {},
      "like_count": 0,
      "views": 286,
      "category_id": 73,
      "featured_link": null,
      "has_accepted_answer": false,
      "posters": [
        {
          "extras": null,
          "description": "原始发帖人",
          "user": {
            "id": 6688,
            "username": "bgwang",
            "name": "",
            "avatar_template": "/letter_avatar_proxy/v4/letter/b/dbc845/{size}.png"
          }
        },
        {
          "extras": "latest",
          "description": "最新发帖人",
          "user": {
            "id": 976,
            "username": "Jaxon",
            "name": "霍格沃兹-修然",
            "avatar_template": "/user_avatar/ceshiren.com/jaxon/{size}/9558_2.png"
          }
        }
      ]
    },
    {
      "id": 15784,
      "title": "files = open(filename, 'r', encoding='utf-8') E FileNotFoundError: [Errno 2]",
      "fancy_title": "files = open(filename, &lsquo;r&rsquo;, encoding=&lsquo;utf-8&rsquo;) E FileNotFoundError: [Errno 2]",
      "slug": "topic",
      "posts_count": 4,
      "reply_count": 0,
      "highest_post_number": 4,
      "image_url": "https://ceshiren.com/uploads/default/optimized/3X/0/4/04afd0958564025daefb7be87341f60061eea5aa_2_1023x503.png",
      "created_at": "2021-12-13T06:03:09.922Z",
      "last_posted_at": "2021-12-16T00:43:08.068Z",
      "bumped": true,
      "bumped_at": "2021-12-16T00:43:08.068Z",
      "archetype": "regular",
      "unseen": false,
      "pinned": false,
      "unpinned": null,
      "visible": true,
      "closed": false,
      "archived": false,
      "bookmarked": null,
      "liked": null,
      "tags": [],
      "tags_descriptions": {},
      "like_count": 0,
      "views": 279,
      "category_id": 73,
      "featured_link": null,
      "has_accepted_answer": false,
      "posters": [
        {
          "extras": "latest",
          "description": "原始发帖人、最新发帖人",
          "user": {
            "id": 5205,
            "username": "sunflower",
            "name": "sunflower",
            "avatar_template": "/letter_avatar_proxy/v4/letter/s/a5b964/{size}.png"
          }
        },
        {
          "extras": null,
          "description": "频繁发帖人",
          "user": {
            "id": 4903,
            "username": "oscar_lcb",
            "name": "oscar",
            "avatar_template": "/user_avatar/ceshiren.com/oscar_lcb/{size}/15258_2.png"
          }
        },
        {
          "extras": null,
          "description": "频繁发帖人",
          "user": {
            "id": 976,
            "username": "Jaxon",
            "name": "霍格沃兹-修然",
            "avatar_template": "/user_avatar/ceshiren.com/jaxon/{size}/9558_2.png"
          }
        }
      ]
    },
    {
      "id": 15958,
      "title": "webdriver无法打开Chrome,以下是错误提示",
      "fancy_title": "webdriver无法打开Chrome,以下是错误提示",
      "slug": "topic",
      "posts_count": 4,
      "reply_count": 2,
      "highest_post_number": 4,
      "image_url": null,
      "created_at": "2021-12-31T11:19:04.212Z",
      "last_posted_at": "2022-05-30T11:42:31.883Z",
      "bumped": true,
      "bumped_at": "2022-05-30T11:42:31.883Z",
      "archetype": "regular",
      "unseen": false,
      "pinned": false,
      "unpinned": null,
      "visible": true,
      "closed": false,
      "archived": false,
      "bookmarked": null,
      "liked": null,
      "tags": [
        "selenium",
        "open"
      ],
      "tags_descriptions": {},
      "like_count": 0,
      "views": 477,
      "category_id": 73,
      "featured_link": null,
      "has_accepted_answer": false,
      "posters": [
        {
          "extras": null,
          "description": "原始发帖人",
          "user": {
            "id": 7101,
            "username": "user44",
            "name": "你好",
            "avatar_template": "/user_avatar/ceshiren.com/user44/{size}/21491_2.png"
          }
        },
        {
          "extras": null,
          "description": "频繁发帖人",
          "user": {
            "id": 1,
            "username": "seveniruby",
            "name": "思寒",
            "avatar_template": "/user_avatar/ceshiren.com/seveniruby/{size}/2_2.png"
          }
        },
        {
          "extras": "latest",
          "description": "最新发帖人",
          "user": {
            "id": 1521,
            "username": "tianyu",
            "name": "",
            "avatar_template": "/letter_avatar_proxy/v4/letter/t/9f8e36/{size}.png"
          }
        }
      ]
    }
  ],
  "tags": [
    "pytest"
  ],
  "tags_descriptions": {},
  "id": 21103,
  "title": "为什么pytest数据驱动多采用yaml,而不采用excel",
  "fancy_title": "为什么pytest数据驱动多采用yaml,而不采用excel",
  "posts_count": 1,
  "created_at": "2022-06-02T05:34:06.161Z",
  "views": 13,
  "reply_count": 0,
  "like_count": 0,
  "last_posted_at": "2022-06-02T05:34:06.222Z",
  "visible": true,
  "closed": false,
  "archived": false,
  "has_summary": false,
  "archetype": "regular",
  "slug": "topic",
  "category_id": 73,
  "word_count": 2,
  "deleted_at": null,
  "user_id": 3962,
  "featured_link": null,
  "pinned_globally": false,
  "pinned_at": null,
  "pinned_until": null,
  "image_url": null,
  "slow_mode_seconds": 0,
  "draft": null,
  "draft_key": "topic_21103",
  "draft_sequence": null,
  "unpinned": null,
  "pinned": false,
  "current_post_number": 1,
  "highest_post_number": 1,
  "deleted_by": null,
  "actions_summary": [
    {
      "id": 4,
      "count": 0,
      "hidden": false,
      "can_act": false
    },
    {
      "id": 8,
      "count": 0,
      "hidden": false,
      "can_act": false
    },
    {
      "id": 7,
      "count": 0,
      "hidden": false,
      "can_act": false
    }
  ],
  "chunk_size": 20,
  "bookmarked": false,
  "bookmarks": [],
  "topic_timer": null,
  "message_bus_last_id": 3,
  "participant_count": 1,
  "show_read_indicator": false,
  "thumbnails": null,
  "slow_mode_enabled_until": null,
  "details": {
    "can_edit": false,
    "notification_level": 1,
    "participants": [
      {
        "id": 3962,
        "username": "conneyma",
        "name": "conneyma",
        "avatar_template": "/letter_avatar_proxy/v4/letter/c/a88e4f/{size}.png",
        "post_count": 1,
        "primary_group_name": null,
        "flair_name": null,
        "flair_url": null,
        "flair_color": null,
        "flair_bg_color": null,
        "trust_level": 0
      }
    ],
    "created_by": {
      "id": 3962,
      "username": "conneyma",
      "name": "conneyma",
      "avatar_template": "/letter_avatar_proxy/v4/letter/c/a88e4f/{size}.png"
    },
    "last_poster": {
      "id": 3962,
      "username": "conneyma",
      "name": "conneyma",
      "avatar_template": "/letter_avatar_proxy/v4/letter/c/a88e4f/{size}.png"
    }
  }
}

1 个赞