[英]pytest warning during excel file handling xlrd
我創建了一個簡單的pytest示例,其中我打開了一個excel文件並計算了工作表的數量並聲明了它。
測試用例通過了,但是我不知何故得到了14條警告。 如何刪除這些警告?
設置:帶有6個工作表的test.xlsx文件。
test_main.py
import xlrd
# ----------------------------------------------------------------------
def test_open_file():
"""
Open and read an Excel file
"""
path = "test.xlsx"
book = xlrd.open_workbook(path)
# print number of sheets
print(book.nsheets)
assert book.nsheets == 6
# ----------------------------------------------------------------------
if __name__ == "__main__":
test_open_file()
然后我運行命令pytest -v。
結果:
============================================================================= test session starts ==============================================================================
platform win32 -- Python 3.7.0, pytest-4.1.0, py-1.7.0, pluggy-0.8.0 -- c:\users\testuser\appdata\local\programs\python\python37\python.exe
cachedir: .pytest_cache
rootdir: C:\Users\testuser\PycharmProjects\testingpytest\testing, inifile:
collected 1 item
test_main.py::test_open_file PASSED [100%]
=============================================================================== warnings summary ===============================================================================
test_main.py::test_open_file
c:\users\testuser\appdata\local\programs\python\python37\lib\site-packages\defusedxml\ElementTree.py:68: DeprecationWarning: The html argument of XMLParser() is deprecated
_XMLParser.__init__(self, html, target, encoding)
c:\users\testuser\appdata\local\programs\python\python37\lib\site-packages\defusedxml\ElementTree.py:68: DeprecationWarning: The html argument of XMLParser() is deprecated
_XMLParser.__init__(self, html, target, encoding)
c:\users\testuser\appdata\local\programs\python\python37\lib\site-packages\defusedxml\ElementTree.py:68: DeprecationWarning: The html argument of XMLParser() is deprecated
_XMLParser.__init__(self, html, target, encoding)
c:\users\testuser\appdata\local\programs\python\python37\lib\site-packages\xlrd\xlsx.py:266: PendingDeprecationWarning: This method will be removed in future versions. Use 'tr
ee.iter()' or 'list(tree.iter())' instead.
for elem in self.tree.iter() if Element_has_iter else self.tree.getiterator():
c:\users\testuser\appdata\local\programs\python\python37\lib\site-packages\defusedxml\ElementTree.py:68: DeprecationWarning: The html argument of XMLParser() is deprecated
_XMLParser.__init__(self, html, target, encoding)
c:\users\testuser\appdata\local\programs\python\python37\lib\site-packages\xlrd\xlsx.py:312: PendingDeprecationWarning: This method will be removed in future versions. Use 'tr
ee.iter()' or 'list(tree.iter())' instead.
for elem in self.tree.iter() if Element_has_iter else self.tree.getiterator():
c:\users\testuser\appdata\local\programs\python\python37\lib\site-packages\defusedxml\ElementTree.py:68: DeprecationWarning: The html argument of XMLParser() is deprecated
_XMLParser.__init__(self, html, target, encoding)
c:\users\testuser\appdata\local\programs\python\python37\lib\site-packages\xlrd\xlsx.py:266: PendingDeprecationWarning: This method will be removed in future versions. Use 'tr
ee.iter()' or 'list(tree.iter())' instead.
for elem in self.tree.iter() if Element_has_iter else self.tree.getiterator():
c:\users\testuser\appdata\local\programs\python\python37\lib\site-packages\defusedxml\ElementTree.py:68: DeprecationWarning: The html argument of XMLParser() is deprecated
_XMLParser.__init__(self, html, target, encoding)
c:\users\testuser\appdata\local\programs\python\python37\lib\site-packages\defusedxml\ElementTree.py:68: DeprecationWarning: The html argument of XMLParser() is deprecated
_XMLParser.__init__(self, html, target, encoding)
c:\users\testuser\appdata\local\programs\python\python37\lib\site-packages\defusedxml\ElementTree.py:68: DeprecationWarning: The html argument of XMLParser() is deprecated
_XMLParser.__init__(self, html, target, encoding)
c:\users\testuser\appdata\local\programs\python\python37\lib\site-packages\defusedxml\ElementTree.py:68: DeprecationWarning: The html argument of XMLParser() is deprecated
_XMLParser.__init__(self, html, target, encoding)
c:\users\testuser\appdata\local\programs\python\python37\lib\site-packages\defusedxml\ElementTree.py:68: DeprecationWarning: The html argument of XMLParser() is deprecated
_XMLParser.__init__(self, html, target, encoding)
c:\users\testuser\appdata\local\programs\python\python37\lib\site-packages\defusedxml\ElementTree.py:68: DeprecationWarning: The html argument of XMLParser() is deprecated
_XMLParser.__init__(self, html, target, encoding)
-- Docs: https://docs.pytest.org/en/latest/warnings.html
==================================================================== 1 passed, 14 warnings in 0.13 seconds =====================================================================
您可以暫時忽略警告(在導入警告模塊之后):
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=PendingDeprecationWarning)
warnings.filterwarnings("ignore", category=DeprecationWarning)
book = xlrd.open_workbook(path)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.