I have tests on a function that uses and modifies global variables. I would like to make sure that my global variable is reset between my tests. Any trick to do that?
main.py:
y = 0
def inc(x):
# side effect
global y
y = y + 1
return x + y + 1
test_main.py:
from main import inc
def test_answer():
assert inc(3) == 5
def test_answer_again():
assert inc(3) == 5
_________________________________________________________________________________________ test_answer_again __________________________________________________________________________________________
def test_answer_again():
> assert inc(3) == 5
E assert 6 == 5
E + where 6 = inc(3)
test_main.py:8: AssertionError
====================================================================================== short test summary info =======================================================================================
FAILED test_main.py::test_answer_again - assert 6 == 5
==================================================================================== 1 failed, 1 passed in 0.01s =====================================================================================