问题描述
下面有一个与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 (将#修改为@)