Pytest-ValueError: I/O operation on closed file.错误排查

在调用pytest -v命令时,出现了ValueError: I/O operation on closed file.错误。
初步定位是logger导致的问题,但无法准确知道报错原因,最终定位到是sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf8')导致的问题,具体原因不详。

只能知道问题出在Logger上面,我的load_setting__init__.py文件下,每次都会初始化这个函数,所以从这里面找问题,查找会用到logger的地方。


深入到fresh_print函数所在文件,注释掉sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf8')后发现问题被修复。

posted @ 2022-08-10 09:05  吹神  阅读(662)  评论(1编辑  收藏  举报