{"id":76733,"date":"2026-02-23T08:26:24","date_gmt":"2026-02-23T00:26:24","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/76733.html"},"modified":"2026-02-23T08:26:24","modified_gmt":"2026-02-23T00:26:24","slug":"pytest%e5%86%92%e7%83%9f%e6%b5%8b%e8%af%95%e7%94%a8%e4%be%8b%e8%bf%87%e6%bb%a4%e6%89%a7%e8%a1%8c%e5%ae%9e%e4%be%8b","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/76733.html","title":{"rendered":"pytest\u5192\u70df\u6d4b\u8bd5\u7528\u4f8b\u8fc7\u6ee4\u6267\u884c\u5b9e\u4f8b"},"content":{"rendered":"<p>\u5982\u4f55\u5728\u5e9e\u5927\u7684\u5168\u91cf\u6d4b\u8bd5\u96c6\u4e2d&#xff0c;\u7cbe\u51c6\u5b9a\u4f4d\u5e76\u6267\u884c\u6838\u5fc3\u94fe\u8def&#xff0c;\u800c\u65e0\u9700\u91cd\u6784\u6574\u4e2a\u6d4b\u8bd5\u751f\u6001\u3002<\/p>\n<h3>\u5b9e\u6218\u65b9\u6848\u8bbe\u8ba1<\/h3>\n<p>\u6838\u5fc3\u601d\u8def&#xff1a;\u65b9\u6848\u4e00\u63d0\u4f9b\u7269\u7406\u9694\u79bb\u7684\u76ee\u5f55\u7ed3\u6784&#xff0c;\u9002\u5408\u7a33\u5b9a\u7248\u672c\u5feb\u901f\u9a8c\u8bc1&#xff1b;\u65b9\u6848\u4e8c\u63d0\u4f9b\u52a8\u6001\u4f18\u5148\u7ea7\u8fc7\u6ee4&#xff0c;\u652f\u6301\u6309\u9700\u7075\u6d3b\u8c03\u5ea6\u3002\u4e24\u8005\u7ed3\u5408&#xff0c;\u53ef\u4ee5\u8986\u76d6\u5927\u591a\u6570\u4e1a\u52a1\u573a\u666f\u3002<\/p>\n<p>\u5b9e\u4f8b\u7ed3\u6784&#xff1a;<\/p>\n<p>test_project\/<br \/>\n\u251c\u2500\u2500 conftest.py                # pytest\u94a9\u5b50\u914d\u7f6e<br \/>\n\u251c\u2500\u2500 pytest.ini                 # pytest\u914d\u7f6e\u6587\u4ef6<br \/>\n\u251c\u2500\u2500 requirements.txt           # \u4f9d\u8d56\u5305<br \/>\n\u251c\u2500\u2500 test_smoke\/                # \u65b9\u6848\u4e00&#xff1a;\u5192\u70df\u7528\u4f8b\u72ec\u7acb\u76ee\u5f55<br \/>\n\u2502   \u251c\u2500\u2500 test_login.py<br \/>\n\u2502   \u2514\u2500\u2500 test_checkout.py<br \/>\n\u251c\u2500\u2500 test_full\/                 # \u65b9\u6848\u4e00&#xff1a;\u5168\u91cf\u7528\u4f8b\u76ee\u5f55<br \/>\n\u2502   \u251c\u2500\u2500 test_login.py<br \/>\n\u2502   \u251c\u2500\u2500 test_checkout.py<br \/>\n\u2502   \u251c\u2500\u2500 test_profile.py<br \/>\n\u2502   \u2514\u2500\u2500 test_orders.py<br \/>\n\u251c\u2500\u2500 test_cases\/                # \u65b9\u6848\u4e8c&#xff1a;YAML\u7528\u4f8b\u96c6\u4e2d\u7ba1\u7406<br \/>\n\u2502   \u251c\u2500\u2500 login.yaml<br \/>\n\u2502   \u251c\u2500\u2500 checkout.yaml<br \/>\n\u2502   \u2514\u2500\u2500 profile.yaml<br \/>\n\u2514\u2500\u2500 run_tests.py               # \u65b9\u6848\u4e8c&#xff1a;\u81ea\u5b9a\u4e49\u547d\u4ee4\u884c\u53c2\u6570\u5904\u7406<\/p>\n<h3>\u6838\u5fc3\u4ee3\u7801\u5b9e\u73b0<\/h3>\n<h4>1. pytest.ini&#xff08;pytest\u57fa\u7840\u914d\u7f6e&#xff09;<\/h4>\n<p>[pytest]<br \/>\ntestpaths &#061; .<br \/>\npython_files &#061; test_*.py<br \/>\npython_classes &#061; Test*<br \/>\npython_functions &#061; test_*<br \/>\naddopts &#061; -v &#8211;tb&#061;short<br \/>\nmarkers &#061;<br \/>\n    smoke: \u5192\u70df\u6d4b\u8bd5\u6807\u8bb0<br \/>\n    blocker: \u9ad8\u4f18\u5148\u7ea7\u963b\u585e\u95ee\u9898<br \/>\n    critical: \u5173\u952e\u4f18\u5148\u7ea7\u95ee\u9898<br \/>\n    normal: \u666e\u901a\u4f18\u5148\u7ea7\u95ee\u9898<\/p>\n<h4>2. conftest.py&#xff08;pytest\u94a9\u5b50\u4e0e\u81ea\u5b9a\u4e49\u53c2\u6570&#xff09;<\/h4>\n<p>import pytest<br \/>\nfrom typing import List, Dict<br \/>\nimport yaml<br \/>\nimport os<\/p>\n<p>def pytest_addoption(parser):<br \/>\n    &#034;&#034;&#034;\u81ea\u5b9a\u4e49\u547d\u4ee4\u884c\u53c2\u6570&#034;&#034;&#034;<br \/>\n    parser.addoption(&#034;&#8211;level&#034;, action&#061;&#034;store&#034;, default&#061;None,<br \/>\n                    help&#061;&#034;\u6307\u5b9a\u7528\u4f8b\u4f18\u5148\u7ea7: blocker,critical,normal&#034;)<br \/>\n    parser.addoption(&#034;&#8211;cases&#034;, action&#061;&#034;store&#034;, default&#061;None,<br \/>\n                    help&#061;&#034;\u6307\u5b9a\u7528\u4f8b\u76ee\u5f55\u8def\u5f84&#034;)<br \/>\n    parser.addoption(&#034;&#8211;type&#034;, action&#061;&#034;store&#034;, default&#061;None,<br \/>\n                    help&#061;&#034;\u6307\u5b9a\u7528\u4f8b\u7c7b\u578b: yaml, python&#034;)<\/p>\n<p>def pytest_configure(config):<br \/>\n    &#034;&#034;&#034;\u52a8\u6001\u6ce8\u518cmarker&#034;&#034;&#034;<br \/>\n    config.addinivalue_line(&#034;markers&#034;, &#034;smoke: \u5192\u70df\u6d4b\u8bd5&#034;)<br \/>\n    config.addinivalue_line(&#034;markers&#034;, &#034;blocker: \u963b\u585e\u7ea7\u522b&#034;)<br \/>\n    config.addinivalue_line(&#034;markers&#034;, &#034;critical: \u5173\u952e\u7ea7\u522b&#034;)<br \/>\n    config.addinivalue_line(&#034;markers&#034;, &#034;normal: \u666e\u901a\u7ea7\u522b&#034;)<\/p>\n<p>def pytest_collection_modifyitems(config, items):<br \/>\n    &#034;&#034;&#034;\u52a8\u6001\u8fc7\u6ee4\u7528\u4f8b&#xff08;\u65b9\u6848\u4e8c\u5b9e\u73b0&#xff09;&#034;&#034;&#034;<br \/>\n    level &#061; config.getoption(&#034;&#8211;level&#034;)<br \/>\n    if not level:<br \/>\n        return<\/p>\n<p>    levels &#061; level.split(&#034;,&#034;)<br \/>\n    selected_items &#061; []<\/p>\n<p>    for item in item:<br \/>\n        # \u83b7\u53d6\u7528\u4f8b\u7684\u6240\u6709marker<br \/>\n        markers &#061; {mark.name for mark in item.iter_markers()}<\/p>\n<p>        # \u68c0\u67e5\u662f\u5426\u5339\u914d\u6307\u5b9a\u4f18\u5148\u7ea7<br \/>\n        if any(lvl in markers for lvl in levels):<br \/>\n            selected_items.append(item)<\/p>\n<p>    items[:] &#061; selected_items<br \/>\n    if selected_items:<br \/>\n        config.hook.pytest_deselected(items&#061;items)<\/p>\n<h4>3. run_tests.py&#xff08;\u65b9\u6848\u4e8c\u7684YAML\u89e3\u6790\u5668&#xff09;<\/h4>\n<p>import pytest<br \/>\nimport yaml<br \/>\nimport os<br \/>\nfrom typing import List, Dict<\/p>\n<p>def case_parser(case_type: str, case_dir: str, level: str &#061; None) -&gt; Dict:<br \/>\n    &#034;&#034;&#034;<br \/>\n    YAML\u7528\u4f8b\u89e3\u6790\u5668&#xff08;\u65b9\u6848\u4e8c\u6838\u5fc3\u903b\u8f91&#xff09;<\/p>\n<p>    Args:<br \/>\n        case_type: \u7528\u4f8b\u7c7b\u578b&#xff0c;\u5982 &#039;yaml&#039;<br \/>\n        case_dir: \u7528\u4f8b\u76ee\u5f55\u8def\u5f84<br \/>\n        level: \u4f18\u5148\u7ea7\u8fc7\u6ee4\u6761\u4ef6<\/p>\n<p>    Returns:<br \/>\n        \u5305\u542b\u8fc7\u6ee4\u540e\u7528\u4f8b\u4fe1\u606f\u7684\u5b57\u5178<br \/>\n    &#034;&#034;&#034;<br \/>\n    case_infos &#061; []<\/p>\n<p>    if case_type !&#061; &#034;yaml&#034;:<br \/>\n        return {&#034;case_infos&#034;: case_infos}<\/p>\n<p>    # \u904d\u5386\u76ee\u5f55\u83b7\u53d6\u6240\u6709YAML\u6587\u4ef6<br \/>\n    yaml_files &#061; []<br \/>\n    for root, _, files in os.walk(case_dir):<br \/>\n        for file in files:<br \/>\n            if file.endswith((&#039;.yaml&#039;, &#039;.yml&#039;)):<br \/>\n                yaml_files.append(os.path.join(root, file))<\/p>\n<p>    # \u89e3\u6790YAML\u7528\u4f8b<br \/>\n    yaml_case_infos &#061; []<br \/>\n    for yaml_file in yaml_files:<br \/>\n        with open(yaml_file, &#039;r&#039;, encoding&#061;&#039;utf-8&#039;) as f:<br \/>\n            data &#061; yaml.safe_load(f)<br \/>\n            if isinstance(data, list):<br \/>\n                yaml_case_infos.extend(data)<br \/>\n            else:<br \/>\n                yaml_case_infos.append(data)<\/p>\n<p>    # \u6839\u636e\u4f18\u5148\u7ea7\u8fc7\u6ee4&#xff08;\u65b9\u6848\u4e8c\u5173\u952e\u903b\u8f91&#xff09;<br \/>\n    if level:<br \/>\n        levels &#061; level.split(&#034;,&#034;)<br \/>\n        for case_info in yaml_case_infos:<br \/>\n            if case_info.get(&#034;rank&#034;) in levels:<br \/>\n                case_infos.append(case_info)<br \/>\n    else:<br \/>\n        case_infos &#061; yaml_case_infos<\/p>\n<p>    return {&#034;case_infos&#034;: case_infos}<\/p>\n<p>def pytest_generate_tests(metafunc):<br \/>\n    &#034;&#034;&#034;\u52a8\u6001\u751f\u6210\u6d4b\u8bd5\u7528\u4f8b&#xff08;YAML\u7528\u4f8b\u6ce8\u5165&#xff09;&#034;&#034;&#034;<br \/>\n    if &#034;case_info&#034; in metafunc.fixturenames:<br \/>\n        case_dir &#061; metafunc.config.getoption(&#034;&#8211;cases&#034;)<br \/>\n        case_type &#061; metafunc.config.getoption(&#034;&#8211;type&#034;)<br \/>\n        level &#061; metafunc.config.getoption(&#034;&#8211;level&#034;)<\/p>\n<p>        if case_dir and case_type:<br \/>\n            result &#061; case_parser(case_type, case_dir, level)<br \/>\n            metafunc.parametrize(&#034;case_info&#034;, result[&#034;case_infos&#034;])<\/p>\n<h4>4. \u65b9\u6848\u4e00&#xff1a;\u76ee\u5f55\u5206\u79bb\u7684\u6d4b\u8bd5\u7528\u4f8b<\/h4>\n<p>test_smoke\/test_login.py<\/p>\n<p>import pytest<\/p>\n<p>&#064;pytest.mark.smoke<br \/>\ndef test_login_success():<br \/>\n    &#034;&#034;&#034;\u5192\u70df\u6d4b\u8bd5&#xff1a;\u767b\u5f55\u6210\u529f&#034;&#034;&#034;<br \/>\n    print(&#034;\u6267\u884c\u5192\u70df\u6d4b\u8bd5&#xff1a;\u767b\u5f55\u6210\u529f&#034;)<br \/>\n    assert True<\/p>\n<p>&#064;pytest.mark.smoke<br \/>\ndef test_login_with_valid_credentials():<br \/>\n    &#034;&#034;&#034;\u5192\u70df\u6d4b\u8bd5&#xff1a;\u6709\u6548\u51ed\u8bc1\u767b\u5f55&#034;&#034;&#034;<br \/>\n    print(&#034;\u6267\u884c\u5192\u70df\u6d4b\u8bd5&#xff1a;\u6709\u6548\u51ed\u8bc1\u767b\u5f55&#034;)<br \/>\n    assert True<\/p>\n<p>test_smoke\/test_checkout.py<\/p>\n<p>import pytest<\/p>\n<p>&#064;pytest.mark.smoke<br \/>\n&#064;pytest.mark.blocker<br \/>\ndef test_checkout_basic_flow():<br \/>\n    &#034;&#034;&#034;\u5192\u70df\u6d4b\u8bd5&#xff1a;\u57fa\u7840\u8d2d\u7269\u6d41\u7a0b&#034;&#034;&#034;<br \/>\n    print(&#034;\u6267\u884c\u5192\u70df\u6d4b\u8bd5&#xff1a;\u57fa\u7840\u8d2d\u7269\u6d41\u7a0b&#034;)<br \/>\n    assert True<\/p>\n<p>test_full\/test_login.py&#xff08;\u5305\u542b\u66f4\u591a\u8fb9\u754c\u573a\u666f&#xff09;<\/p>\n<p>import pytest<\/p>\n<p>&#064;pytest.mark.smoke<br \/>\ndef test_login_success():<br \/>\n    &#034;&#034;&#034;\u5168\u91cf\u6d4b\u8bd5&#xff1a;\u767b\u5f55\u6210\u529f&#034;&#034;&#034;<br \/>\n    assert True<\/p>\n<p>&#064;pytest.mark.normal<br \/>\ndef test_login_with_invalid_password():<br \/>\n    &#034;&#034;&#034;\u5168\u91cf\u6d4b\u8bd5&#xff1a;\u9519\u8bef\u5bc6\u7801\u767b\u5f55&#034;&#034;&#034;<br \/>\n    assert True<\/p>\n<p>&#064;pytest.mark.normal<br \/>\ndef test_login_with_empty_fields():<br \/>\n    &#034;&#034;&#034;\u5168\u91cf\u6d4b\u8bd5&#xff1a;\u7a7a\u5b57\u6bb5\u767b\u5f55&#034;&#034;&#034;<br \/>\n    assert True<\/p>\n<p>&#064;pytest.mark.critical<br \/>\ndef test_login_with_locked_account():<br \/>\n    &#034;&#034;&#034;\u5168\u91cf\u6d4b\u8bd5&#xff1a;\u9501\u5b9a\u8d26\u53f7\u767b\u5f55&#034;&#034;&#034;<br \/>\n    assert True<\/p>\n<h4>5. \u65b9\u6848\u4e8c&#xff1a;YAML\u7528\u4f8b\u6587\u4ef6<\/h4>\n<p>test_cases\/login.yaml<\/p>\n<p>&#8211; desc: \u767b\u5f55\u7528\u4f8b-\u6b63\u5e38\u767b\u5f55<br \/>\n  rank: blocker<br \/>\n  steps:<br \/>\n    &#8211; step: \u6253\u5f00\u767b\u5f55\u9875\u9762<br \/>\n      expected: \u9875\u9762\u52a0\u8f7d\u6210\u529f<br \/>\n    &#8211; step: \u8f93\u5165\u7528\u6237\u540d\u5bc6\u7801<br \/>\n      expected: \u8f93\u5165\u6210\u529f<br \/>\n    &#8211; step: \u70b9\u51fb\u767b\u5f55\u6309\u94ae<br \/>\n      expected: \u767b\u5f55\u6210\u529f\u8df3\u8f6c<\/p>\n<p>&#8211; desc: \u767b\u5f55\u7528\u4f8b-\u9519\u8bef\u5bc6\u7801<br \/>\n  rank: normal<br \/>\n  steps:<br \/>\n    &#8211; step: \u6253\u5f00\u767b\u5f55\u9875\u9762<br \/>\n      expected: \u9875\u9762\u52a0\u8f7d\u6210\u529f<br \/>\n    &#8211; step: \u8f93\u5165\u7528\u6237\u540d\u548c\u9519\u8bef\u5bc6\u7801<br \/>\n      expected: \u8f93\u5165\u6210\u529f<br \/>\n    &#8211; step: \u70b9\u51fb\u767b\u5f55\u6309\u94ae<br \/>\n      expected: \u63d0\u793a\u5bc6\u7801\u9519\u8bef<\/p>\n<p>&#8211; desc: \u767b\u5f55\u7528\u4f8b-\u9501\u5b9a\u8d26\u53f7<br \/>\n  rank: critical<br \/>\n  steps:<br \/>\n    &#8211; step: \u6253\u5f00\u767b\u5f55\u9875\u9762<br \/>\n      expected: \u9875\u9762\u52a0\u8f7d\u6210\u529f<br \/>\n    &#8211; step: \u8f93\u5165\u9501\u5b9a\u8d26\u53f7<br \/>\n      expected: \u8f93\u5165\u6210\u529f<br \/>\n    &#8211; step: \u70b9\u51fb\u767b\u5f55\u6309\u94ae<br \/>\n      expected: \u63d0\u793a\u8d26\u53f7\u5df2\u9501\u5b9a<\/p>\n<p>test_cases\/checkout.yaml<\/p>\n<p>&#8211; desc: \u8d2d\u7269\u6d41\u7a0b-\u57fa\u7840\u6d41\u7a0b<br \/>\n  rank: blocker<br \/>\n  steps:<br \/>\n    &#8211; step: \u9009\u62e9\u5546\u54c1<br \/>\n      expected: \u5546\u54c1\u9009\u4e2d<br \/>\n    &#8211; step: \u52a0\u5165\u8d2d\u7269\u8f66<br \/>\n      expected: \u8d2d\u7269\u8f66\u6570\u91cf\u589e\u52a0<br \/>\n    &#8211; step: \u63d0\u4ea4\u8ba2\u5355<br \/>\n      expected: \u8ba2\u5355\u63d0\u4ea4\u6210\u529f<\/p>\n<p>&#8211; desc: \u8d2d\u7269\u6d41\u7a0b-\u5e93\u5b58\u4e0d\u8db3<br \/>\n  rank: critical<br \/>\n  steps:<br \/>\n    &#8211; step: \u9009\u62e9\u5e93\u5b58\u4e0d\u8db3\u5546\u54c1<br \/>\n      expected: \u5546\u54c1\u9009\u4e2d<br \/>\n    &#8211; step: \u52a0\u5165\u8d2d\u7269\u8f66<br \/>\n      expected: \u63d0\u793a\u5e93\u5b58\u4e0d\u8db3<\/p>\n<h4>6. YAML\u7528\u4f8b\u9a71\u52a8\u6d4b\u8bd5&#xff08;\u65b9\u6848\u4e8c\u6267\u884c\u5668&#xff09;<\/h4>\n<p>test_yaml_runner.py<\/p>\n<p>import pytest<\/p>\n<p>def test_yaml_case(case_info):<br \/>\n    &#034;&#034;&#034;<br \/>\n    YAML\u7528\u4f8b\u901a\u7528\u6267\u884c\u5668<br \/>\n    \u901a\u8fc7conftest.py\u4e2d\u7684pytest_generate_tests\u52a8\u6001\u6ce8\u5165\u7528\u4f8b<br \/>\n    &#034;&#034;&#034;<br \/>\n    print(f&#034;\\\\n\u6267\u884c\u7528\u4f8b&#xff1a;{case_info[&#039;desc&#039;]}&#034;)<br \/>\n    print(f&#034;\u4f18\u5148\u7ea7&#xff1a;{case_info.get(&#039;rank&#039;, &#039;\u65e0&#039;)}&#034;)<\/p>\n<p>    for idx, step in enumerate(case_info[&#039;steps&#039;], 1):<br \/>\n        print(f&#034;\u6b65\u9aa4{idx}: {step[&#039;step&#039;]}&#034;)<br \/>\n        print(f&#034;\u9884\u671f: {step[&#039;expected&#039;]}&#034;)<br \/>\n        # \u8fd9\u91cc\u53ef\u4ee5\u6dfb\u52a0\u5b9e\u9645\u7684\u6d4b\u8bd5\u903b\u8f91<br \/>\n        # \u4f8b\u5982\u8c03\u7528API\u3001\u64cd\u4f5c\u9875\u9762\u7b49<\/p>\n<p>    assert True  # \u7b80\u5316\u793a\u4f8b&#xff0c;\u5b9e\u9645\u5e94\u6839\u636e\u6b65\u9aa4\u6267\u884c\u7ed3\u679c\u65ad\u8a00<\/p>\n<h4>7. requirements.txt<\/h4>\n<p>pytest&gt;&#061;7.0.0<br \/>\npyyaml&gt;&#061;6.0<br \/>\npytest-html&gt;&#061;3.0.0<\/p>\n<h3>\u6267\u884c\u793a\u4f8b\u4e0e\u547d\u4ee4<\/h3>\n<h4>\u65b9\u6848\u4e00&#xff1a;\u76ee\u5f55\u5206\u79bb\u6a21\u5f0f\u6267\u884c<\/h4>\n<p># \u53ea\u6267\u884c\u5192\u70df\u6d4b\u8bd5&#xff08;\u6307\u5b9asmoke\u76ee\u5f55&#xff09;<br \/>\npytest test_smoke\/ -v<\/p>\n<p># \u6267\u884c\u5168\u91cf\u6d4b\u8bd5&#xff08;\u6307\u5b9afull\u76ee\u5f55&#xff09;<br \/>\npytest test_full\/ -v<\/p>\n<p># \u4f7f\u7528\u81ea\u5b9a\u4e49\u53c2\u6570\u6267\u884c\u5192\u70df\u6d4b\u8bd5<br \/>\npytest &#8211;cases&#061;.\/test_smoke &#8211;type&#061;python -v<\/p>\n<h4>\u65b9\u6848\u4e8c&#xff1a;\u4f18\u5148\u7ea7\u8fc7\u6ee4\u6a21\u5f0f\u6267\u884c<\/h4>\n<p># \u53ea\u6267\u884cblocker\u548ccritical\u7ea7\u522b\u7528\u4f8b&#xff08;\u5192\u70df\u6d4b\u8bd5&#xff09;<br \/>\npytest &#8211;level&#061;blocker,critical -v<\/p>\n<p># \u6267\u884c\u6307\u5b9a\u7ea7\u522b\u7528\u4f8b<br \/>\npytest &#8211;level&#061;normal -v<\/p>\n<p># \u7ed3\u5408YAML\u7528\u4f8b\u6267\u884c<br \/>\npytest test_yaml_runner.py &#8211;cases&#061;.\/test_cases &#8211;type&#061;yaml &#8211;level&#061;blocker,critical -v<\/p>\n<h4>\u7ec4\u5408\u573a\u666f\u6267\u884c<\/h4>\n<p># \u6267\u884c\u5192\u70df\u76ee\u5f55 &#043; blocker\u7ea7\u522b\u7528\u4f8b<br \/>\npytest test_smoke\/ &#8211;level&#061;blocker -v<\/p>\n<p># \u5e76\u884c\u6267\u884c\u591a\u4e2a\u6d4b\u8bd5\u96c6\u5408<br \/>\npytest test_smoke\/ test_full\/ &#8211;level&#061;blocker,critical -v<\/p>\n<h3>\u5b9e\u4f8b\u4eae\u70b9\u4e0e\u6700\u4f73\u5b9e\u8df5\u4f53\u73b0<\/h3>\n<li>\n<p>\u65b9\u6848\u4e00\u4f53\u73b0&#xff1a;<\/p>\n<ul>\n<li>test_smoke\/\u00a0\u548c\u00a0test_full\/\u00a0\u7269\u7406\u5206\u79bb&#xff0c;\u7ed3\u6784\u6e05\u6670<\/li>\n<li>\u901a\u8fc7 pytest \u547d\u4ee4\u76f4\u63a5\u6307\u5b9a\u76ee\u5f55\u6267\u884c&#xff0c;\u7b80\u5355\u9ad8\u6548<\/li>\n<li>\u9002\u5408\u9879\u76ee\u7a33\u5b9a\u540e&#xff0c;\u5192\u70df\u7528\u4f8b\u4e0d\u5e38\u53d8\u5316\u7684\u573a\u666f<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u65b9\u6848\u4e8c\u4f53\u73b0&#xff1a;<\/p>\n<ul>\n<li>YAML \u7528\u4f8b\u7edf\u4e00\u7ba1\u7406&#xff0c;\u4fbf\u4e8e\u7ef4\u62a4\u548c\u7248\u672c\u63a7\u5236<\/li>\n<li>\u901a\u8fc7\u00a0&#8211;level\u00a0\u53c2\u6570\u52a8\u6001\u8fc7\u6ee4&#xff0c;\u652f\u6301\u7075\u6d3b\u8c03\u5ea6<\/li>\n<li>\u9002\u5408\u7528\u4f8b\u9891\u7e41\u8c03\u6574\u3001\u9700\u8981\u6309\u4f18\u5148\u7ea7\u5206\u6279\u6267\u884c\u7684\u573a\u666f<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u4e24\u8005\u7ed3\u5408&#xff1a;<\/p>\n<ul>\n<li>\u76ee\u5f55\u5206\u79bb\u5904\u7406\u6838\u5fc3\u7a33\u5b9a\u94fe\u8def&#xff08;\u5982\u767b\u5f55\u3001\u652f\u4ed8&#xff09;<\/li>\n<li>YAML &#043; \u4f18\u5148\u7ea7\u5904\u7406\u9700\u8981\u52a8\u6001\u8c03\u6574\u7684\u4e1a\u52a1\u573a\u666f&#xff08;\u5982\u8425\u9500\u6d3b\u52a8&#xff09;<\/li>\n<li>\u901a\u8fc7\u540c\u4e00\u4e2a\u914d\u7f6e\u4f53\u7cfb&#xff08;pytest.ini &#043; conftest.py&#xff09;\u7edf\u4e00\u7ba1\u7406<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u5de5\u7a0b\u5316\u7ec6\u8282&#xff1a;<\/p>\n<ul>\n<li>pytest \u94a9\u5b50\u5b9e\u73b0\u52a8\u6001\u8fc7\u6ee4&#xff0c;\u65e0\u9700\u4fee\u6539\u6d4b\u8bd5\u4ee3\u7801<\/li>\n<li>Marker \u4f53\u7cfb\u6807\u51c6\u5316\u7528\u4f8b\u5206\u7c7b<\/li>\n<li>YAML \u89e3\u6790\u5668\u652f\u6301\u4f18\u5148\u7ea7\u5b57\u6bb5\u8fc7\u6ee4&#xff0c;\u5b8c\u5168\u590d\u73b0\u4f60\u63d0\u4f9b\u7684\u903b\u8f91<\/li>\n<\/ul>\n<\/li>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u5728\u5e9e\u5927\u7684\u5168\u91cf\u6d4b\u8bd5\u96c6\u4e2d&#xff0c;\u7cbe\u51c6\u5b9a\u4f4d\u5e76\u6267\u884c\u6838\u5fc3\u94fe\u8def&#xff0c;\u800c\u65e0\u9700\u91cd\u6784\u6574\u4e2a\u6d4b\u8bd5\u751f\u6001\u3002\u5b9e\u6218\u65b9\u6848\u8bbe\u8ba1\u6838\u5fc3\u601d\u8def&#xff1a;\u65b9\u6848\u4e00\u63d0\u4f9b\u7269\u7406\u9694\u79bb\u7684\u76ee\u5f55\u7ed3\u6784&#xff0c;\u9002\u5408\u7a33\u5b9a\u7248\u672c\u5feb\u901f\u9a8c\u8bc1&#xff1b;\u65b9\u6848\u4e8c\u63d0\u4f9b\u52a8\u6001\u4f18\u5148\u7ea7\u8fc7\u6ee4&#xff0c;\u652f\u6301\u6309\u9700\u7075\u6d3b\u8c03\u5ea6\u3002\u4e24\u8005\u7ed3\u5408&#xff0c;\u53ef\u4ee5\u8986\u76d6\u5927\u591a\u6570\u4e1a\u52a1\u573a\u666f\u3002\u5b9e\u4f8b\u7ed3\u6784&#xff1a;test_project\/<br \/>\n\u251c\u2500\u2500 conftest.py                # pytest\u94a9\u5b50\u914d\u7f6e<br \/>\n\u251c\u2500\u2500 pyte<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[4327,149,138],"topic":[],"class_list":["post-76733","post","type-post","status-publish","format-standard","hentry","category-server","tag-pytest","tag-windows","tag-138"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>pytest\u5192\u70df\u6d4b\u8bd5\u7528\u4f8b\u8fc7\u6ee4\u6267\u884c\u5b9e\u4f8b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/76733.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"pytest\u5192\u70df\u6d4b\u8bd5\u7528\u4f8b\u8fc7\u6ee4\u6267\u884c\u5b9e\u4f8b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u5982\u4f55\u5728\u5e9e\u5927\u7684\u5168\u91cf\u6d4b\u8bd5\u96c6\u4e2d&#xff0c;\u7cbe\u51c6\u5b9a\u4f4d\u5e76\u6267\u884c\u6838\u5fc3\u94fe\u8def&#xff0c;\u800c\u65e0\u9700\u91cd\u6784\u6574\u4e2a\u6d4b\u8bd5\u751f\u6001\u3002\u5b9e\u6218\u65b9\u6848\u8bbe\u8ba1\u6838\u5fc3\u601d\u8def&#xff1a;\u65b9\u6848\u4e00\u63d0\u4f9b\u7269\u7406\u9694\u79bb\u7684\u76ee\u5f55\u7ed3\u6784&#xff0c;\u9002\u5408\u7a33\u5b9a\u7248\u672c\u5feb\u901f\u9a8c\u8bc1&#xff1b;\u65b9\u6848\u4e8c\u63d0\u4f9b\u52a8\u6001\u4f18\u5148\u7ea7\u8fc7\u6ee4&#xff0c;\u652f\u6301\u6309\u9700\u7075\u6d3b\u8c03\u5ea6\u3002\u4e24\u8005\u7ed3\u5408&#xff0c;\u53ef\u4ee5\u8986\u76d6\u5927\u591a\u6570\u4e1a\u52a1\u573a\u666f\u3002\u5b9e\u4f8b\u7ed3\u6784&#xff1a;test_project\/ \u251c\u2500\u2500 conftest.py        # pytest\u94a9\u5b50\u914d\u7f6e \u251c\u2500\u2500 pyte\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/76733.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-02-23T00:26:24+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/76733.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/76733.html\",\"name\":\"pytest\u5192\u70df\u6d4b\u8bd5\u7528\u4f8b\u8fc7\u6ee4\u6267\u884c\u5b9e\u4f8b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-02-23T00:26:24+00:00\",\"dateModified\":\"2026-02-23T00:26:24+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/76733.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/76733.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/76733.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"pytest\u5192\u70df\u6d4b\u8bd5\u7528\u4f8b\u8fc7\u6ee4\u6267\u884c\u5b9e\u4f8b\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"pytest\u5192\u70df\u6d4b\u8bd5\u7528\u4f8b\u8fc7\u6ee4\u6267\u884c\u5b9e\u4f8b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/76733.html","og_locale":"zh_CN","og_type":"article","og_title":"pytest\u5192\u70df\u6d4b\u8bd5\u7528\u4f8b\u8fc7\u6ee4\u6267\u884c\u5b9e\u4f8b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u5982\u4f55\u5728\u5e9e\u5927\u7684\u5168\u91cf\u6d4b\u8bd5\u96c6\u4e2d&#xff0c;\u7cbe\u51c6\u5b9a\u4f4d\u5e76\u6267\u884c\u6838\u5fc3\u94fe\u8def&#xff0c;\u800c\u65e0\u9700\u91cd\u6784\u6574\u4e2a\u6d4b\u8bd5\u751f\u6001\u3002\u5b9e\u6218\u65b9\u6848\u8bbe\u8ba1\u6838\u5fc3\u601d\u8def&#xff1a;\u65b9\u6848\u4e00\u63d0\u4f9b\u7269\u7406\u9694\u79bb\u7684\u76ee\u5f55\u7ed3\u6784&#xff0c;\u9002\u5408\u7a33\u5b9a\u7248\u672c\u5feb\u901f\u9a8c\u8bc1&#xff1b;\u65b9\u6848\u4e8c\u63d0\u4f9b\u52a8\u6001\u4f18\u5148\u7ea7\u8fc7\u6ee4&#xff0c;\u652f\u6301\u6309\u9700\u7075\u6d3b\u8c03\u5ea6\u3002\u4e24\u8005\u7ed3\u5408&#xff0c;\u53ef\u4ee5\u8986\u76d6\u5927\u591a\u6570\u4e1a\u52a1\u573a\u666f\u3002\u5b9e\u4f8b\u7ed3\u6784&#xff1a;test_project\/ \u251c\u2500\u2500 conftest.py        # pytest\u94a9\u5b50\u914d\u7f6e \u251c\u2500\u2500 pyte","og_url":"https:\/\/www.wsisp.com\/helps\/76733.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-02-23T00:26:24+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/76733.html","url":"https:\/\/www.wsisp.com\/helps\/76733.html","name":"pytest\u5192\u70df\u6d4b\u8bd5\u7528\u4f8b\u8fc7\u6ee4\u6267\u884c\u5b9e\u4f8b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-02-23T00:26:24+00:00","dateModified":"2026-02-23T00:26:24+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/76733.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/76733.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/76733.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"pytest\u5192\u70df\u6d4b\u8bd5\u7528\u4f8b\u8fc7\u6ee4\u6267\u884c\u5b9e\u4f8b"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/76733","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=76733"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/76733\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=76733"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=76733"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=76733"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=76733"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}