让pytest了解exec内置功能

问题描述

下面有一个pytest一起运行的简单测试。它通过内置函数exec起作用:

def test_exec() -> None:
    foo = ""  # Causes test to fail if not updated by exec
    exec("foo = 5")
    assert isinstance(foo,int)

pytest之外(通过ipython运行)时,代码可以正常工作。通过pytest运行时,exec语句似乎无法正常运行。

如何将exec函数作为pytest的一部分运行?


版本

Python==3.8.5
pytest==6.1.1

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)