python - Pytest E DeprecationWarning : defusedxml. lxml 不再受支持,将在未来版本中删除

标签 python pytest openpyxl

我有一个简单的Python代码,如下所示:

文件名:test_pytest_openpyxl.py

import openpyxl

def test_1():
    print("test_1")

if __name__ == "__main__":
    test_1()

python test_pytest_openpyxl.py

它通过了,没有错误。然而,

pytest test_pytest_openpyxl.py 出现以下错误:

================================================= test session starts ==================================================
platform linux -- Python 3.7.4, pytest-5.3.3, py-1.8.0, pluggy-0.13.1
plugins: arraydiff-0.3, astropy-header-0.1.1, doctestplus-0.5.0, openfiles-0.4.0, remotedata-0.3.2
collected 0 items / 1 error

======================================================== ERRORS ========================================================
_________________________________________ ERROR collecting test_pytest_xml.py __________________________________________
/home/user/anaconda3/lib/python3.7/site-packages/py/_path/local.py:701: in pyimport
    __import__(modname)
<frozen importlib._bootstrap>:983: in _find_and_load
    ???
<frozen importlib._bootstrap>:967: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:677: in _load_unlocked
    ???
/home/user/anaconda3/lib/python3.7/site-packages/_pytest/assertion/rewrite.py:143: in exec_module
    exec(co, module.__dict__)
C:\Users\v-jonluo\repo\performance\perf_lib\py_lib\gantt_model\pytest\test_pytest_xml.py:1: in <module>
    ???
/home/user/anaconda3/lib/python3.7/site-packages/openpyxl/__init__.py:6: in <module>
    from openpyxl.workbook import Workbook
/home/user/anaconda3/lib/python3.7/site-packages/openpyxl/workbook/__init__.py:5: in <module>
    from .workbook import Workbook
/home/user/anaconda3/lib/python3.7/site-packages/openpyxl/workbook/workbook.py:8: in <module>
    from openpyxl.worksheet.worksheet import Worksheet
/home/user/anaconda3/lib/python3.7/site-packages/openpyxl/worksheet/worksheet.py:30: in <module>
    from openpyxl.cell import Cell, MergedCell
/home/user/anaconda3/lib/python3.7/site-packages/openpyxl/cell/__init__.py:4: in <module>
    from .cell import Cell, WriteOnlyCell, MergedCell
/home/user/anaconda3/lib/python3.7/site-packages/openpyxl/cell/cell.py:46: in <module>
    from openpyxl.utils.inference import (
/home/user/anaconda3/lib/python3.7/site-packages/openpyxl/utils/inference.py:10: in <module>
    from openpyxl.styles import numbers
/home/user/anaconda3/lib/python3.7/site-packages/openpyxl/styles/__init__.py:5: in <module>
    from .alignment import Alignment
/home/user/anaconda3/lib/python3.7/site-packages/openpyxl/styles/alignment.py:6: in <module>
    from openpyxl.descriptors import Bool, MinMax, Min, Alias, NoneSet
/home/user/anaconda3/lib/python3.7/site-packages/openpyxl/descriptors/__init__.py:5: in <module>
    from .sequence import Sequence
/home/user/anaconda3/lib/python3.7/site-packages/openpyxl/descriptors/sequence.py:5: in <module>
    from openpyxl.xml.functions import Element
/home/user/anaconda3/lib/python3.7/site-packages/openpyxl/xml/functions.py:31: in <module>
    from defusedxml.lxml import fromstring as _fromstring, tostring
/home/user/anaconda3/lib/python3.7/site-packages/defusedxml/lxml.py:29: in <module>
    stacklevel=2,
E   DeprecationWarning: defusedxml.lxml is no longer supported and will be removed in a future release.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
=================================================== 1 error in 4.19s ===================================================

环境: Ubuntu 18.04/Windows 10、Pythion 3.7.4、openpyxl 2.6.2、pytest-5.3.3、setuptools 45.1.0

最佳答案

此警告 has been fixed recently

您应该尝试使用更新版本的库来删除它 ( 3.0.3 is available )

关于python - Pytest E DeprecationWarning : defusedxml. lxml 不再受支持,将在未来版本中删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60749381/

相关文章:

python - 加载和保存列表索引超出范围后的openpyxl(python)

Python 无法导入 openpyxl

python - 初学者python问题: Unresolved reference in function arguments (passing variables)

python - 在 Python 中记录方法调用的更好方法?

python - 构建函数以清除字段和 send_keys

python - 如何将 unittest 子测试转换为 pytest

python - 如何使用pytest-qt点击QMessageBox?

python - 根据值替换 DataFrame 中的行

python - 将 pytest 测试相互隔离