{"id":99,"date":"2022-04-09T19:26:17","date_gmt":"2022-04-09T19:26:17","guid":{"rendered":"http:\/\/fanaticboy.com\/?p=99"},"modified":"2022-04-09T19:26:18","modified_gmt":"2022-04-09T19:26:18","slug":"pythonrequestsunittestbeautifulreport%e8%87%aa%e5%8a%a8%e5%8c%96%e6%8e%a5%e5%8f%a3%e6%b5%8b%e8%af%95","status":"publish","type":"post","link":"https:\/\/fanaticboy.com\/?p=99","title":{"rendered":"python+requests+unittest+BeautifulReport\u81ea\u52a8\u5316\u63a5\u53e3\u6d4b\u8bd5"},"content":{"rendered":"\n<p>\u200b<\/p>\n\n\n\n<p>\u5927\u5bb6\u5462\u4e5f\u662f\u4e86\u89e3\u4e86python requests\u7684\u57fa\u672c\u7528\u6cd5\u4e86\uff0c\u90a3\u4e48\u54b1\u4eec\u5c31\u5e94\u7528\u4e0a\u5355\u5143\u6d4b\u8bd5\u6846\u67b6unittest\u8fd8\u6709BeautifulReport\u7b80\u5355\u7684\u5b9e\u73b0\u4e00\u4e0b\u81ea\u52a8\u5316\u7684\u63a5\u53e3\u6d4b\u8bd5<\/p>\n\n\n\n<p>\u4e00\u3001\u642d\u5efa\u6846\u67b6<\/p>\n\n\n\n<p>&nbsp; \u54b1\u4eec\u4e5f\u662f\u770b\u4e00\u4e0b\u56fe\uff0c\u9700\u8981\u521b\u5efa\u7684\u6587\u4ef6\u5939\u4ee5\u53ca\u6587\u4ef6\u90fd\u5728\u8fd9\u91cc\u4e86\uff0c\u6211\u8fd9\u8fb9\u7528\u7684pycharm\uff0c\u5176\u4ed6\u7684\u5f00\u53d1\u5de5\u5177\u4e5f\u90fd\u662f\u5dee\u4e0d\u591a\u7684\u54c8\uff0c\u521b\u5efa\u5b8c\u4e4b\u540e\u54b1\u4eec\u5f00\u59cb\u5f80\u91cc\u9762\u5199\u4ee3\u7801<\/p>\n\n\n\n<p><img decoding=\"async\" alt=\"\" src=\"https:\/\/img-blog.csdnimg.cn\/img_convert\/5a418c0213e18bfa4151fc9f5ebc3a42.png\">\u200b<img loading=\"lazy\" decoding=\"async\" src=\"blob:http:\/\/fanaticboy.com\/3aab8409-8547-480d-aaa4-76945480b7ae\" width=\"15\" height=\"15\"><\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp;\u54b1\u4eec\u4ee5\u5fae\u4fe1\u516c\u4f17\u5e73\u53f0\u7684\u83b7\u53d6token\u7684\u63a5\u53e3\u6765\u8fdb\u884c\u4e00\u4e0b\u6d4b\u8bd5\uff0c\u9996\u5148\u9700\u8981\u83b7\u53d6\u63a5\u53e3\u76f8\u5173\u7684\u6587\u6863\uff0c\u54b1\u4eec\u53ef\u4ee5\u8f93\u5165\u4e0b\u9762\u7684\u94fe\u63a5\uff0c\u5c31\u53ef\u4ee5\u76f4\u63a5\u770bapi\u6587\u6863\u4e86\uff0c\u94fe\u63a5https:\/\/developers.weixin.qq.com\/doc\/offiaccount\/Basic_Information\/Get_access_token.html<\/p>\n\n\n\n<p><img decoding=\"async\" alt=\"\" src=\"https:\/\/img-blog.csdnimg.cn\/img_convert\/db305e12f15d8c795b49d656acd8a557.png\">\u200b<img loading=\"lazy\" decoding=\"async\" src=\"blob:http:\/\/fanaticboy.com\/c915dc36-4816-47ff-92b6-63357c70623c\" width=\"15\" height=\"15\"><\/p>\n\n\n\n<p>\u8bf7\u6c42\u7684\u65b9\u6cd5\u662fget\uff0c\u5176\u4e2d\u6211\u5728\u8fd9\u91cc\u7f57\u5217\u4e00\u4e0b\u9700\u8981\u7684\u8bf7\u6c42\u53c2\u6570<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>\u53c2\u6570<\/th><th>\u662f\u5426\u5fc5\u987b<\/th><th>\u8bf4\u660e<\/th><\/tr><\/thead><tbody><tr><td>grant_type<\/td><td>\u662f<\/td><td>\u83b7\u53d6access_token\u586b \u5199client_credential<\/td><\/tr><tr><td>appid<\/td><td>\u662f<\/td><td>\u7b2c\u4e09\u65b9\u7528\u6237\u552f\u4e00\u51ed\u8bc1<\/td><\/tr><tr><td>secret<\/td><td>\u662f<\/td><td>\u7b2c\u4e09\u65b9\u7528\u6237\u552f\u4e00\u51ed\u8bc1\u5bc6\u94a5<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u81ea\u5df1\u7684appid\u548csecret\u600e\u4e48\u83b7\u53d6\u5230\u5462\uff0c\u8fd9\u4e2a\u9700\u8981\u54b1\u4eec\u6709\u81ea\u5df1\u7684\u516c\u4f17\u53f7\u4e86\uff0c\u5728\u8fd9\u91cc\u54c8\uff0c\u5982\u56fe\u6240\u793a\uff0c\u57fa\u672c\u7684\u53c2\u6570\u6709\u4e86\u4e4b\u540e\uff0c\u54b1\u4eec\u5c31\u53ef\u4ee5\u8fdb\u884c\u6d4b\u8bd5\u4e86<\/p>\n\n\n\n<p><img decoding=\"async\" alt=\"\" src=\"https:\/\/img-blog.csdnimg.cn\/img_convert\/c6af4444dc0e7f090ed1e43fce09fd60.png\">\u200b<img loading=\"lazy\" decoding=\"async\" src=\"blob:http:\/\/fanaticboy.com\/601e889a-d47b-486f-a7ed-1722061c7421\" width=\"15\" height=\"15\"><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;\u54b1\u4eec\u4f7f\u7528\u6570\u636e\u9a71\u52a8\u7684\u65b9\u6cd5\u8fdb\u884c\u6d4b\u8bd5\uff0c\u6570\u636e\u5728json\u6587\u4ef6\u4e2d\uff0c\u54b1\u4eec\u5148\u5199\u4e00\u4e2ajson\u6587\u4ef6\u5185\u5bb9\u5982\u4e0b\uff0c\u91cc\u9762\u5199\u7684\u6709url\uff0c\u8fd8\u6709\u54b1\u4eec\u8bf7\u6c42\u7684\u5fc5\u8981\u53c2\u6570<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>[<\/code><code>  {<\/code><code>    \"path\": {<\/code><code>    \"url\": \"https:\/\/api.weixin.qq.com\/cgi-bin\/token\"<\/code><code>  },<\/code><code>    \"params\": {<\/code><code>    \"grant_type\": \"client_credential\",<\/code><code>    \"appid\": \"\u81ea\u5df1\u7684\",<\/code><code>    \"secret\": \"\u81ea\u5df1\u7684\"<\/code><code>  }<\/code><code>  }<\/code><code>]<\/code><\/pre>\n\n\n\n<p>\u6570\u636e\u653e\u5728data\u6587\u4ef6\u5939\u91cc\u9762<\/p>\n\n\n\n<p><img decoding=\"async\" alt=\"\" src=\"https:\/\/img-blog.csdnimg.cn\/img_convert\/d4abcbf51d1960bc09483864299db138.png\">\u200b<img loading=\"lazy\" decoding=\"async\" src=\"blob:http:\/\/fanaticboy.com\/6397f06f-30ee-4dde-b403-3a46f53de8f0\" width=\"15\" height=\"15\"><\/p>\n\n\n\n<p>\u63a5\u4e0b\u6765\u662f\u6d4b\u8bd5\u7528\u4f8b\u7684\u7f16\u5199\uff0c\u5176\u4e2d\u65ad\u8a00\u90e8\u5206\u662f\u4e0e\u8fd4\u56de\u7684\u6570\u636e\u4f5c\u5bf9\u6bd4\uff0c\u53ef\u4ee5\u770b\u51fa\u5982\u679c\u53c2\u6570\u5bf9\uff0c\u8fd4\u56de\u7684\u6570\u636e\u5e94\u8be5\u662f\u4ee5\u4e0b\u8fd9\u6837\u7684\uff0c\u6240\u4ee5\u4e0e\u8fd9\u4e2a7200\u4f5c\u6bd4\u8f83\uff0c\u8fd4\u56de\u7684\u6570\u636e\u91cc\u9762\u67097200\uff0c\u5c31\u8bf4\u660e\u8fd9\u4e2a\u6210\u529f\u4e86<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\"access_token\":\"ACCESS_TOKEN\",\"expires_in\":7200}<\/code><\/pre>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" src=\"blob:http:\/\/fanaticboy.com\/9f8512a5-ca28-4407-83cc-4d6f3fb296b5\" width=\"15\" height=\"15\"><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\u6d4b\u8bd5\u7528\u4f8b\u5982\u4e0b<\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>from pyparsing import ParseExpression\nimport requests\nimport json\nimport unittest\nfrom ddt import data, ddt, file_data\n# from HTMLTestRunner import HTMLTestRunner\n@ddt\nclass UnittestDemo(unittest.TestCase):\n    @classmethod\n    def setUpClass(cls) -&gt; None:\n        pass\n\u200b\n    @classmethod\n    def tearDownClass(cls) -&gt; None:\n        pass\n&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;\u91c7\u7528ddt\u65b9\u5f0f\u6570\u636e\u9a71\u52a8\uff0c\u5730\u5740\u5c31\u662f\u5199\u7684json\u7684\u8def\u5f84\n    @file_data(\"D:\/interfacetest\/apiDemo\/data\/testwechat.json\")\n    def test_01(self, **kwargs):\n        print(kwargs&#91;\"path\"]&#91;\"url\"])\n        \"\"\"\n        \u6b63\u5411\u7684\u6d4b\u8bd5\u7528\u4f8b\n        :param kwargs:\n        :return:\n        \"\"\"\n        response = requests.get(url=kwargs&#91;\"path\"]&#91;\"url\"], params=kwargs&#91;\"params\"])\n        expectValue = '7200'\n        acutalValue = str(response.json()&#91;\"expires_in\"])\n        self.assertIn(expectValue, acutalValue)\n        print(\"\u8bf7\u6c42\u6570\u636e\uff1a\", kwargs)<\/code><\/pre>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" src=\"blob:http:\/\/fanaticboy.com\/8f2e39a5-fe43-4f56-9627-878855dcf111\" width=\"15\" height=\"15\"><\/p>\n\n\n\n<p>&nbsp; &nbsp; \u4e8c\u3001\u4ee3\u7801\u6267\u884c<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp;\u63a5\u4e0b\u6765\u5c31\u662f\u4e3b\u51fd\u6570\u4e86\uff0c\u4e3b\u51fd\u6570\u54b1\u4eec\u91c7\u7528BeautifulReport\u5b9e\u73b0\uff0c\u5177\u4f53\u7684\u4ee3\u7801\u5982\u4e0b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from BeautifulReport import BeautifulReport\nimport unittest\nif __name__ == '__main__':\n    discover = unittest.defaultTestLoader.discover(\".\/test_case\", pattern=\"testwechat.py\")\n    BeautifulReport(discover).report(\"\u6267\u884c\u7528\u4f8b\", filename=\"res.html\", report_dir=\".\/reports\")<\/code><\/pre>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" src=\"blob:http:\/\/fanaticboy.com\/f9604624-76ca-404c-866e-80d878254f29\" width=\"15\" height=\"15\"><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;\u770b\u4e00\u4e0b\u6267\u884c\u7684\u6548\u679c\uff0c\u4e0b\u9762\u5c31\u662f\u6d4b\u8bd5\u62a5\u544a\u4e86<\/p>\n\n\n\n<p><img decoding=\"async\" alt=\"\" src=\"https:\/\/img-blog.csdnimg.cn\/img_convert\/80c3a674fa056cb5b0e2e6c5db7ed063.png\">\u200b<img loading=\"lazy\" decoding=\"async\" src=\"blob:http:\/\/fanaticboy.com\/765e7e89-2918-4544-b2be-c4576cf78453\" width=\"15\" height=\"15\"><\/p>\n\n\n\n<p>\u4ee5\u4e0a\u5c31\u662f\u54b1\u4eec\u7b80\u5355\u7684\u81ea\u52a8\u5316\u63a5\u53e3\u6d4b\u8bd5\u4e86\u4ee5\u540e\u8fd8\u4f1a\u5b9a\u671f\u66f4\u65b0\u65b0\u5185\u5bb9\u54c8 \u200b<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u200b \u5927\u5bb6\u5462\u4e5f\u662f\u4e86\u89e3\u4e86python requests\u7684\u57fa\u672c\u7528\u6cd5\u4e86\uff0c\u90a3\u4e48\u54b1\u4eec\u5c31\u5e94\u7528\u4e0a\u5355\u5143\u6d4b\u8bd5\u6846\u67b6unittest\u8fd8 &#8230; <a title=\"python+requests+unittest+BeautifulReport\u81ea\u52a8\u5316\u63a5\u53e3\u6d4b\u8bd5\" class=\"read-more\" href=\"https:\/\/fanaticboy.com\/?p=99\" aria-label=\"\u9605\u8bfb python+requests+unittest+BeautifulReport\u81ea\u52a8\u5316\u63a5\u53e3\u6d4b\u8bd5\">\u9605\u8bfb\u66f4\u591a<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15,2,9],"tags":[],"class_list":["post-99","post","type-post","status-publish","format-standard","hentry","category-python","category-postman","category-script"],"_links":{"self":[{"href":"https:\/\/fanaticboy.com\/index.php?rest_route=\/wp\/v2\/posts\/99","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fanaticboy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fanaticboy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fanaticboy.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fanaticboy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=99"}],"version-history":[{"count":1,"href":"https:\/\/fanaticboy.com\/index.php?rest_route=\/wp\/v2\/posts\/99\/revisions"}],"predecessor-version":[{"id":100,"href":"https:\/\/fanaticboy.com\/index.php?rest_route=\/wp\/v2\/posts\/99\/revisions\/100"}],"wp:attachment":[{"href":"https:\/\/fanaticboy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=99"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fanaticboy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=99"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fanaticboy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=99"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}