{
  "version": "https://jsonfeed.org/version/1", 
  "title": "pytest", 
  "description": "\u5173\u4e8e Python \u5355\u5143\u6d4b\u8bd5\u6846\u67b6 pytest \u7684\u4f7f\u7528\u4ea4\u6d41", 
  "home_page_url": "https://www.v2ex.com/go/pytest", 
  "feed_url": "https://www.v2ex.com/feed/pytest.json", 
  "icon": "https://cdn.v2ex.com/navatar/d93e/d5b6/984_large.png?m=1495313877", 
  "favicon": "https://cdn.v2ex.com/navatar/d93e/d5b6/984_normal.png?m=1495313877", 
  "items": [
    {
      "author": {
        "url": "https://www.v2ex.com/member/ALLROBOT", 
        "name": "ALLROBOT", 
        "avatar": "https://cdn.v2ex.com/avatar/eb31/6d3f/333565_large.png?m=1737196994"
      }, 
      "url": "https://www.v2ex.com/t/925004", 
      "date_modified": "2023-03-17T20:42:43+00:00", 
      "content_html": "<p>playwright \u6587\u6863\u63d0\u5230\u7684 pytest \u6d4b\u8bd5\u4f8b\u5b50\uff0c\u4e2a\u4eba\u7528\u4e86\u4e0b\uff0c\u611f\u89c9 pytest \u7684 debug \u633a\u65b9\u4fbf\u7684\u6837\u5b50\uff0c\u80fd\u76f4\u63a5\u8f93\u51fa\u5e38\u91cf\u3001\u53d8\u91cf\u503c\uff0c\u7701\u4e86\u5199\u65ad\u8a00\u6761\u4ef6\u7684\u529f\u592b\uff0c\u76f4\u767d\u544a\u8bc9\u4f60\u662f\u54ea\u91cc\u641e\u9519\u4e86</p>\n<p>\u4e2a\u4eba\u6bd4\u8f83\u4e1a\u4f59\uff0c\u53ea\u4f1a Python \u5199\u70b9\u4e1c\u897f\uff0c\u641e\u4e0d\u61c2\u4e00\u4e9b\u88c5\u9970\u5668\u5e72\u5565\u7528\u7684\uff0c\u770b API \u53c2\u8003\u6ca1\u80fd\u6574\u660e\u767d</p>\n<p>\u6709\u4ec0\u4e48\u9879\u76ee\u4f9b\u7ec3\u624b\uff0c\u6700\u5927\u6316\u6398\u3001\u66f4\u719f\u6089 pytest \uff1f</p>\n", 
      "date_published": "2023-03-17T19:41:20+00:00", 
      "title": "pytest \u6c42\u51e0\u4e2a\u9879\u76ee\u7ec3\u624b", 
      "id": "https://www.v2ex.com/t/925004"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/duzhonglin", 
        "name": "duzhonglin", 
        "avatar": "https://cdn.v2ex.com/avatar/a5d8/4a66/358081_large.png?m=1540435670"
      }, 
      "url": "https://www.v2ex.com/t/554373", 
      "title": "pytest \u5b89\u88c5\u5230\u865a\u62df\u73af\u5883", 
      "id": "https://www.v2ex.com/t/554373", 
      "date_published": "2019-04-12T03:11:47+00:00", 
      "content_html": "python \u4ee3\u7801\u8c03\u7528 pytest \u63d0\u793a\u627e\u4e0d\u5230 pytest \u6a21\u5757\uff0c\u5220\u9664\u865a\u62df\u73af\u5883\u540e\u662f\u6b63\u5e38\u7684\uff0c\u4e0d\u6653\u5f97\u662f\u4ec0\u4e48\u539f\u56e0\u5462\uff1f"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/iyaozhen", 
        "name": "iyaozhen", 
        "avatar": "https://cdn.v2ex.com/avatar/6406/09f6/68154_large.png?m=1758465562"
      }, 
      "url": "https://www.v2ex.com/t/329934", 
      "date_modified": "2017-05-20T20:58:14+00:00", 
      "content_html": "<p>\u5927\u6982\u7684\u4ee3\u7801\u662f\u8fd9\u6837\uff1a</p>\n<pre><code>import requests\nimport pytest\n\nclass TestRestApi():\n    url = 'http://xxx.com'\n\n    @pytest.fixture(scope=\"session\")\n    def http_session(self):\n        # \u7701\u7565\u8bbe\u7f6e cookie \u7b49\u6b65\u9aa4\uff0c\u8fd4\u56de\u4e00\u4e2a request.session \u5bf9\u8c61\n        return requests.Session()\n\n    def test_api_a(self, http_session):\n        response = http_session.post(self.url + '/app/sessioncontextget', json=body)\n        assert response.status_code == 200\n        data = response.json()\n        # \u6211\u60f3\u4fdd\u5b58\u6b64 api \u7684\u4e00\u4e2a\u8fd4\u56de\u503c\n        self.session_id = data['data']['session_id']\n        assert data['code'] == 200\n\n    def test_api_b(self, http_session):\n        body = {\n            # \u8bf7\u6c42\u53c2\u6570\u4f9d\u8d56\u524d\u4e00\u4e2a api \u7684\u8fd4\u56de\u503c\n            \"sessionid\": self.session_id,\n        }\n        response = http_session.post(self.url_ge + '/api/taskcreate', json=body)\n        assert response.status_code == 200\n        data = response.json()\n        assert data['errcode'] == 0\n\n</code></pre>\n<p>\u65ad\u70b9\u8c03\u8bd5\u53d1\u73b0 session_id \u662f\u8bbe\u7f6e\u6210\u529f\u4e86\u7684\uff0c test_api_a \u4e5f\u6d4b\u8bd5\u901a\u8fc7</p>\n<p><img alt=\"\" src=\"http://ws3.sinaimg.cn/large/98d2e36bjw1fb2715ajwjj20tw03sq4c.jpg\"></p>\n<p>\u4f46\u8fd0\u884c\u5230 test_api_b \u65f6\u5374\u63d0\u793a\uff1aAttributeError: 'TestRestApi' object has no attribute 'session_id'\u3002\u4e0d\u8fc7\u8fd9\u4e5f\u5f88\u597d\u7406\u89e3\uff0c\u5355\u6d4b\u672c\u6765\u5c31\u662f\u6bcf\u4e2a case \u72ec\u7acb\u7684\uff0c\u6bcf\u6b21\u76f8\u5f53\u4e8e\u90fd\u662f\u91cd\u65b0\u8fd0\u884c\u3002</p>\n<p>\u90a3\u4e48\u95ee\u9898\u6765\u4e86\uff0c\u8fd9\u4e2a\u9700\u6c42\u600e\u4e48\u89e3\u51b3\uff1f</p>\n<p>\u8fd8\u6709\u4e00\u4e2a\u95ee\u9898\uff0c pytest.fixture \u7684\u7279\u6027\u611f\u89c9\u4e0d\u662f\u5f88\u65b9\u4fbf\uff0c http_session \u53d8\u91cf\u65e0\u6cd5\u88ab IDE \u8bc6\u522b\uff0c\u6ca1\u6709\u4ee3\u7801\u63d0\u793a\u4e86\uff08\u4e0d\u8fc7\u8fd9\u4e2a\u5f71\u54cd\u5f88\u5c0f\uff09\uff0c\u5173\u952e\u662f\u6bcf\u4e2a\u6d4b\u8bd5 case \u90fd\u8981\u4f20\u5165 http_session \u53c2\u6570\uff0c\u611f\u89c9\u4e0d\u591f\u7b80\u6d01\u3002</p>\n<p>\u521d\u6b21\u4f7f\u7528 py.test \uff0c\u53ef\u80fd\u7406\u89e3\u4e0d\u662f\u5f88\u900f\u5f7b\uff0c\u8fd8\u8bf7\u89c1\u8c05\u3002</p>\n", 
      "date_published": "2016-12-24T13:29:02+00:00", 
      "title": "\u8bf7\u6559\u4e2a py.test \u7684\u4f7f\u7528\u95ee\u9898\uff08 case \u95f4\u53c2\u6570\u4f9d\u8d56\uff09", 
      "id": "https://www.v2ex.com/t/329934"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/clarkchen", 
        "name": "clarkchen", 
        "avatar": "https://cdn.v2ex.com/avatar/42af/dcd3/21455_large.png?m=1767067686"
      }, 
      "url": "https://www.v2ex.com/t/318451", 
      "date_modified": "2017-05-20T20:58:18+00:00", 
      "content_html": "<p>\u5e73\u5e38\u4e3b\u8981\u662f\u4f9d\u9760 Python(PyCharm) + Java(Intellij)\u505a\u5f00\u53d1</p>\n<p>\u5bf9\u4e8e\u67d0\u4e00\u4e2a\u7528\u6237\u81ea\u5b9a\u4e49\u7684\u65b9\u6cd5\u90fd\u53ef\u4ee5\u901a\u8fc7 Navigate-&gt;Test \u6765\u521b\u5efa\u5355\u6d4b</p>\n<p>\u7528 Intellij \u7684 Maven \u6846\u67b6\u7684\u8bdd\uff0c\u521b\u5efa\u5355\u5143\u6d4b\u8bd5\u975e\u5e38\u8212\u670d\uff0c\u81ea\u52a8\u4f1a\u5728\u5bf9\u5e94\u7684 test \u76ee\u5f55\u4e0b\u9762\u5efa\u7acb\u76f8\u5e94\u7684\u6587\u4ef6</p>\n<p>\u4f8b\u5982\nsrc/main/java/abc/run.java\n\u5bf9\u5e94\u7684\u6d4b\u8bd5\u6587\u4ef6\u662f\ntest/java/abc/runTest.java</p>\n<p>\u4f46\u662f Pycharm \u5c31\u86cb\u75bc\u4e86\uff0c\u540c\u6837\u81ea\u52a8\u521b\u5efa\u5355\u5143\u6d4b\u8bd5\uff0c\u5176\u76ee\u5f55\u7ed3\u6784\u76f4\u63a5\u5c31\u662f\u5728\u76f8\u540c\u76ee\u5f55\u4e0b\u521b\u5efa\n\u4f8b\u5982\u5728 src \u76ee\u5f55\u4e0b\nsrc/abc/<a href=\"http://run.py\" rel=\"nofollow\">run.py</a>\n\u81ea\u52a8\u521b\u5efa\u7684\u6587\u4ef6\u4f4d\u7f6e\nsrc/abc/<a href=\"http://test_run.py\" rel=\"nofollow\">test_run.py</a></p>\n<p>\u5de8\u4e11\uff0c\uff0c</p>\n<p>\u76ee\u524d\u6211\u662f\u624b\u52a8\u96c6\u4e2d\u5230\u4e00\u4e2a\u65b0\u5efa\u7684 test \u76ee\u5f55\u4e0b\uff0c\u5c3d\u91cf\u6a21\u4eff Maven \u683c\u5f0f\uff0c\u4f46\u603b\u89c9\u7684\u8def\u5b50\u6709\u70b9\u91ce</p>\n<p>\u4e0d\u77e5\u9053\u6709\u6728\u6709 Python \u5927\u795e\uff0c\u77e5\u9053\u6b63\u89c4 or \u4eba\u6027\u5316 \u7684 Python \u5355\u6d4b\u65b9\u6cd5</p>\n", 
      "date_published": "2016-11-06T04:01:51+00:00", 
      "title": "Python \u86cb\u75bc\u7684\u5355\u5143\u6d4b\u8bd5", 
      "id": "https://www.v2ex.com/t/318451"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/loveshouhu", 
        "name": "loveshouhu", 
        "avatar": "https://cdn.v2ex.com/avatar/5d2c/bbbc/38329_large.png?m=1367397101"
      }, 
      "url": "https://www.v2ex.com/t/96126", 
      "date_modified": "2017-05-20T20:58:27+00:00", 
      "content_html": "\u6700\u8fd1\u60f3\u4e86\u89e3\u70b9\u5173\u4e8ePython\u5355\u5143\u6d4b\u8bd5\u6846\u67b6\u7684\u4e1c\u897f\u3002<br />\u5927\u5bb6\u6709\u63a8\u8350\u5417\u3002<br /><br />\u767e\u5ea6\u4e86\u4e00\u4e0b\uff0c\u6ca1\u53d1\u73b0\u7279\u522b\u6709\u5206\u6790\u6027\u7684\u6587\u5b57\u3002<br /><br />PyUnit  nose \u4ec0\u4e48\u7684\u6709\u63a8\u8350\u5417\uff1f", 
      "date_published": "2014-01-08T03:52:24+00:00", 
      "title": "\u5173\u4e8ePython\u5355\u5143\u6d4b\u8bd5\u6846\u67b6", 
      "id": "https://www.v2ex.com/t/96126"
    }
  ]
}