I have a simple test below that I run with pytest
. It works via the built-in function exec
:
def test_exec() -> None:
foo = "" # Causes test to fail if not updated by exec
exec("foo = 5")
assert isinstance(foo, int)
When run outside of pytest
(via ipython
), the code works fine. When run via pytest
, the exec
statement doesn't seem to be run properly.
How can I run an exec
function as part of a pytest
?
Versions
Python==3.8.5
pytest==6.1.1