最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

pytest配置文件pytest.ini的詳細(xì)使用

 更新時(shí)間:2021年04月16日 16:51:27   作者:小菠蘿測(cè)試筆記  
這篇文章主要介紹了pytest配置文件pytest.ini的詳細(xì)使用,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

前言

pytest配置文件可以改變pytest的運(yùn)行方式,它是一個(gè)固定的文件pytest.ini文件,讀取配置信息,按指定的方式去運(yùn)行

非test文件

pytest里面有些文件是非test文件

  • pytest.ini:pytest的主配置文件,可以改變pytest的默認(rèn)行為
  • conftest.py:測(cè)試用例的一些fixture配置
  • _init_.py:識(shí)別該文件夾為python的package包

查看pytest.ini的配置選項(xiàng)

cmd執(zhí)行

pytest --help

找到這部分內(nèi)容

[pytest] ini-options in the first pytest.ini|tox.ini|setup.cfg file found:

  markers (linelist):   markers for test functions
  empty_parameter_set_mark (string):
                        default marker for empty parametersets
  norecursedirs (args): directory patterns to avoid for recursion
  testpaths (args):     directories to search for tests when no files or directories are given in the command line.
  usefixtures (args):   list of default fixtures to be used with this project
  python_files (args):  glob-style file patterns for Python test module discovery
  python_classes (args):
                        prefixes or glob names for Python test class discovery
  python_functions (args):
                        prefixes or glob names for Python test function and method discovery
  disable_test_id_escaping_and_forfeit_all_rights_to_community_support (bool):
                        disable string escape non-ascii characters, might cause unwanted side effects(use at your own
                        risk)
  console_output_style (string):
                        console output: "classic", or with additional progress information ("progress" (percentage) |
                        "count").
  xfail_strict (bool):  default for the strict parameter of xfail markers when not given explicitly (default: False)
  enable_assertion_pass_hook (bool):
                        Enables the pytest_assertion_pass hook.Make sure to delete any previously generated pyc cache
                        files.
  junit_suite_name (string):
                        Test suite name for JUnit report
  junit_logging (string):
                        Write captured log messages to JUnit report: one of no|log|system-out|system-err|out-err|all
  junit_log_passing_tests (bool):
                        Capture log information for passing tests to JUnit report:
  junit_duration_report (string):
                        Duration time to report: one of total|call
  junit_family (string):
                        Emit XML for schema: one of legacy|xunit1|xunit2
  doctest_optionflags (args):
                        option flags for doctests
  doctest_encoding (string):
                        encoding used for doctest files
  cache_dir (string):   cache directory path.
  filterwarnings (linelist):
                        Each line specifies a pattern for warnings.filterwarnings. Processed after -W/--pythonwarnings.
  log_print (bool):     default value for --no-print-logs
  log_level (string):   default value for --log-level
  log_format (string):  default value for --log-format
  log_date_format (string):
                        default value for --log-date-format
  log_cli (bool):       enable log display during test run (also known as "live logging").
  log_cli_level (string):
                        default value for --log-cli-level
  log_cli_format (string):
                        default value for --log-cli-format
  log_cli_date_format (string):
                        default value for --log-cli-date-format
  log_file (string):    default value for --log-file
  log_file_level (string):
                        default value for --log-file-level
  log_file_format (string):
                        default value for --log-file-format
  log_file_date_format (string):
                        default value for --log-file-date-format
  log_auto_indent (string):
                        default value for --log-auto-indent
  faulthandler_timeout (string):
                        Dump the traceback of all threads if a test takes more than TIMEOUT seconds to finish. Not
                        available on Windows.
  addopts (args):       extra command line options
  minversion (string):  minimally required pytest version
  rsyncdirs (pathlist): list of (relative) paths to be rsynced for remote distributed testing.
  rsyncignore (pathlist):
                        list of (relative) glob-style paths to be ignored for rsyncing.
  looponfailroots (pathlist):
                        directories to check for changes

pytest.ini應(yīng)該放哪里?

就放在項(xiàng)目根目錄下 ,不要亂放,不要亂起其他名字

接下來講下常用的配置項(xiàng)

marks

作用:測(cè)試用例中添加了 @pytest.mark.webtest 裝飾器,如果不添加marks選項(xiàng)的話,就會(huì)報(bào)warnings

格式:list列表類型

寫法:

[pytest]
markers =
    weibo: this is weibo page
    toutiao: toutiao
    xinlang: xinlang

xfail_strict

作用:設(shè)置xfail_strict = True可以讓那些標(biāo)記為@pytest.mark.xfail但實(shí)際通過顯示XPASS的測(cè)試用例被報(bào)告為失敗

格式:True 、False(默認(rèn)),1、0

寫法:

[pytest]

# mark標(biāo)記說明
markers =
    weibo: this is weibo page
    toutiao: toutiao
    xinlang: xinlang

xfail_strict = True

具體代碼栗子

未設(shè)置 xfail_strict = True 時(shí),測(cè)試結(jié)果顯示XPASS

@pytest.mark.xfail()
def test_case1():
    a = "a"
    b = "b"
    assert a != b

collecting ... collected 1 item

02斷言異常.py::test_case1 XPASS [100%]

============================= 1 xpassed in 0.02s ==============================

已設(shè)置 xfail_strict = True 時(shí),測(cè)試結(jié)果顯示failed

collecting ... collected 1 item

02斷言異常.py::test_case1 FAILED                                         [100%]
02斷言異常.py:54 (test_case1)
[XPASS(strict)] 

================================== FAILURES ===================================
_________________________________ test_case1 __________________________________
[XPASS(strict)] 
=========================== short test summary info ===========================
FAILED 02斷言異常.py::test_case1
============================== 1 failed in 0.02s ==============================

addopts

作用:addopts參數(shù)可以更改默認(rèn)命令行選項(xiàng),這個(gè)當(dāng)我們?cè)赾md輸入一堆指令去執(zhí)行用例的時(shí)候,就可以用該參數(shù)代替了,省去重復(fù)性的敲命令工作

比如:想測(cè)試完生成報(bào)告,失敗重跑兩次,一共運(yùn)行兩次,通過分布式去測(cè)試,如果在cmd中寫的話,命令會(huì)很長(zhǎng)

pytest -v --rerun=2 --count=2 --html=report.html --self-contained-html -n=auto

每次都這樣敲不太現(xiàn)實(shí),addopts就可以完美解決這個(gè)問題

[pytest]

# mark
markers =
    weibo: this is weibo page
    toutiao: toutiao
    xinlang: xinlang

xfail_strict = True

# 命令行參數(shù)
addopts = -v --reruns=1 --count=2 --html=reports.html --self-contained-html -n=auto

加了addopts之后,我們?cè)赾md中只需要敲pytest就可以生效了?。?/p>

log_cli

作用:控制臺(tái)實(shí)時(shí)輸出日志

格式:log_cli=True 或False(默認(rèn)),或者log_cli=1 或 0

log_cli=0的運(yùn)行結(jié)果

log_cli=1的運(yùn)行結(jié)果

結(jié)論

很明顯,加了log_cli=1之后,可以清晰看到哪個(gè)package下的哪個(gè)module下的哪個(gè)測(cè)試用例是否passed還是failed;

所以平時(shí)測(cè)試代碼是否有問題的情況下推薦加?。。〉绻萌ヅ颗軠y(cè)試用例的話不建議加,誰知道會(huì)不會(huì)影響運(yùn)行性能呢?

norecursedirs

作用:pytest 收集測(cè)試用例時(shí),會(huì)遞歸遍歷所有子目錄,包括某些你明知道沒必要遍歷的目錄,遇到這種情況,可以使用 norecursedirs 參數(shù)簡(jiǎn)化 pytest 的搜索工作【還是挺有用的!!!】

默認(rèn)設(shè)置: norecursedirs = .* build dist CVS _darcs {arch} *.egg

正確寫法:多個(gè)路徑用空格隔開

[pytest]

norecursedirs = .* build dist CVS _darcs {arch} *.egg venv src resources log report util

更改測(cè)試用例收集規(guī)則

pytest默認(rèn)的測(cè)試用例收集規(guī)則

  • 文件名以 test_*.py 文件和 *_test.py
  • 以  test_ 開頭的函數(shù)
  • 以  Test 開頭的類,不能包含 __init__ 方法
  • 以  test_ 開頭的類里面的方法

我們是可以修改或者添加這個(gè)用例收集規(guī)則的;當(dāng)然啦,是建議在原有的規(guī)則上添加的,如下配置

[pytest]

python_files =     test_*  *_test  test*
python_classes =   Test*   test*
python_functions = test_*  test*

到此這篇關(guān)于pytest配置文件pytest.ini的詳細(xì)使用的文章就介紹到這了,更多相關(guān)pytest.ini配置內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

兴化市| 鄱阳县| 乌兰浩特市| 麻江县| 津南区| 西盟| 澜沧| 依安县| 广灵县| 温泉县| 柞水县| 哈巴河县| 丰原市| 浦城县| 明水县| 石楼县| 石阡县| 武平县| 伊吾县| 庄浪县| 潞西市| 乐陵市| 义马市| 页游| 清水河县| 玉门市| 华宁县| 桦甸市| 双柏县| 怀仁县| 永定县| 万山特区| 阳原县| 玉山县| 炉霍县| 苗栗市| 扬州市| 聊城市| 河源市| 镇康县| 云霄县|