gpt4 book ai didi

python - 导入失败时pytest打印堆栈跟踪

转载 作者:太空宇宙 更新时间:2023-11-04 10:07:55 24 4
gpt4 key购买 nike

假设一个 python 测试模块生成一个 ImportErrorpytest(版本 3.0.2)生成一个紧凑的错误报告:

__________________________________________ ERROR collecting tests/wc_tests/log/test_logger.py __________________________________________
ImportError while importing test module '/Users/arthur_at_sinai/gitOnMyLaptopLocal/Mpn-Example/tests/wc_tests/log/test_logger.py'.
Original error message:
'No module named 'wc.config.core''
Make sure your test modules/packages have valid Python names.

相比之下,nosetests-3.4 生成一个堆栈跟踪,如下所示:

ERROR: Failure: ImportError (No module named 'wc.config.core')
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/nose/failure.py", line 39, in runTest
raise self.exc_val.with_traceback(self.tb)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/nose/loader.py", line 418, in loadTestsFromName
addr.filename, addr.module)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/nose/importer.py", line 47, in importFromPath
return self.importFromDir(dir_path, fqname)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/nose/importer.py", line 94, in importFromDir
mod = load_module(part_fqname, fh, filename, desc)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/imp.py", line 234, in load_module
return load_source(name, filename, file)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/imp.py", line 172, in load_source
module = _load(spec)
File "<frozen importlib._bootstrap>", line 693, in _load
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 665, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "/Users/arthur_at_sinai/gitOnMyLaptopLocal/Mpn-Example/tests/wc_tests/log/test_logger.py", line 12, in <module>
from wc.sim.core import Simulator
File "/Users/arthur_at_sinai/gitOnMyLaptopLocal/Mpn-Example/wc/sim/core.py", line 16, in <module>
from wc.log.checkpoint import CheckpointLogger
File "/Users/arthur_at_sinai/gitOnMyLaptopLocal/Mpn-Example/wc/log/checkpoint.py", line 9, in <module>
from wc.config.core import config
ImportError: No module named 'wc.config.core'

如何让 pytest 产生类似的堆栈跟踪信息?这些选项可用

-l, --showlocals      show locals in tracebacks (disabled by default).
--tb=style traceback print mode (auto/long/short/line/native/no).
--full-trace don't cut any tracebacks (default is to cut).

但他们都没有为我带来结核病。 pytest -vv 也没有。

谢谢

亚瑟

最佳答案

这是 changed一周前在 pytest 中显示完整的回溯。

如果您不想等待下一个版本,您可以通过 pip install git+https://github.com/pytest-dev/pytest.git 使用 git 存储库中的 pytest > 与此同时。

关于python - 导入失败时pytest打印堆栈跟踪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39982332/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com