亚洲精品久久久久久第一页-人妻少妇精彩视品一区二区三区-91国产自拍免费视频-免费一级a在线播放视频正片-少妇天天日天天射天天爽-国产大屁股喷水视频在线观看-操美女骚穴抽插性爱视频-亚洲 欧美 中文字幕 丝袜-成人免费无码片在线观看

html隨機選數(shù)代碼介紹 html隨機數(shù)生成器( 三 )


[dechin@dechin-manjaro pytest]$ pytest --versionpytest 6.2.2pytest單元測試用例撰寫根據(jù)前面一個章節(jié)中的random_number.py文件,我們可以對照的寫一個簡單測試用例:
# test_random_number.pyimport pytestfrom random_number import random_number_generator as rngdef test_random_number_generator():for i in range(10):random_number = rng()assert random_number == 0 or random_number == 1該測試用例的含義為:導(dǎo)入rng函數(shù)之后,測試10次該函數(shù)的返回值,所返回的值必須是0或者1的隨機數(shù),如果輸出了這兩個數(shù)字以外的返回結(jié)果,那么說明這個隨機數(shù)產(chǎn)生器功能上存在問題 ?;趐ytest的測試代碼可以通過如下的指令來運行:
[dechin@dechin-20n2s01200 pytest]$ py.test=========================================== test session starts ============================================platform linux -- Python 3.8.5, pytest-6.2.2, py-1.9.0, pluggy-0.13.1rootdir: /home/dechin/projects/2021-python/pytestplugins: cov-2.11.1, metadata-1.11.0, html-3.1.1collected 1 itemtest_random_number.py .[100%]============================================= warnings summary =============================================../../../anaconda3/lib/python3.8/site-packages/projectq/ops/_gates.py:118/home/dechin/anaconda3/lib/python3.8/site-packages/projectq/ops/_gates.py:118: PendingDeprecationWarning: the matrix subclass is not the recommended way to represent matrices or deal with linear algebra (see https://docs.scipy.org/doc/numpy/user/numpy-for-matlab-users.html). Please adjust your code to use regular ndarray.return np.matrix([[1, 0], [0, 1j]])../../../anaconda3/lib/python3.8/site-packages/projectq/ops/_gates.py:133/home/dechin/anaconda3/lib/python3.8/site-packages/projectq/ops/_gates.py:133: PendingDeprecationWarning: the matrix subclass is not the recommended way to represent matrices or deal with linear algebra (see https://docs.scipy.org/doc/numpy/user/numpy-for-matlab-users.html). Please adjust your code to use regular ndarray.return np.matrix([[1, 0], [0, cmath.exp(1j * cmath.pi / 4)]])test_random_number.py: 40 warnings/home/dechin/anaconda3/lib/python3.8/site-packages/projectq/ops/_gates.py:69: PendingDeprecationWarning: the matrix subclass is not the recommended way to represent matrices or deal with linear algebra (see https://docs.scipy.org/doc/numpy/user/numpy-for-matlab-users.html). Please adjust your code to use regular ndarray.return 1. / cmath.sqrt(2.) * np.matrix([[1, 1], [1, -1]])-- Docs: https://docs.pytest.org/en/stable/warnings.html====================================== 1 passed, 42 warnings in 0.50s ======================================從返回的結(jié)果來看,出現(xiàn)了1 passed而沒有failed,說明所有的測試用例都已經(jīng)執(zhí)行成功了,但是這里存在不少的告警warnings信息 。
pytest初始化配置文件在上一節(jié)的測試結(jié)果中,我們發(fā)現(xiàn)有非常多的測試告警 。假如我們確認這些告警信息可以忽略,那么我們可以通過在指令中配置忽略告警信息,或者直接使用這里介紹的pytest.ini來忽略相應(yīng)的告警信息:
# pytest.ini[pytest]filterwarnings =ignore::PendingDeprecationWarning在當前目錄下的ini配置文件中,我們添加了PendingDeprecationWarning作為忽略項,然后我們再回頭看一下上述用例的測試結(jié)果:
[dechin@dechin-manjaro pytest]$ py.test=========================================== test session starts ============================================platform linux -- Python 3.8.5, pytest-6.2.2, py-1.9.0, pluggy-0.13.1rootdir: /home/dechin/projects/2021-python/pytest, configfile: pytest.iniplugins: cov-2.11.1, metadata-1.11.0, html-3.1.1collected 1 itemtest_random_number.py .[100%]============================================ 1 passed in 0.50s =============================================這里返回的結(jié)果中就沒有告警信息了 。
pytest生成html格式報告為了更好的展現(xiàn)測試的結(jié)果,這里我們需要先安裝一個組件pytest-html:


以上關(guān)于本文的內(nèi)容,僅作參考!溫馨提示:如遇健康、疾病相關(guān)的問題,請您及時就醫(yī)或請專業(yè)人士給予相關(guān)指導(dǎo)!

「愛刨根生活網(wǎng)」www.malaban59.cn小編還為您精選了以下內(nèi)容,希望對您有所幫助: