I want to test a simple class A:
class A:
_cache = None
def func(self):
if not A._cache:
A._cache = 'Get value from some service'
class TestA:
def test_cache_after_func(self):
a = A()
a.func()
assert A._cache is not None
def test_cache_empty(self):
a = A()
assert A._cache is None
These two tests pass when run separately from VSCode. But when they are run together then second test fails because the first one already has modified the _cache field.
How to run these tests isolated without affecting one another? (I would appreciate examples both for unittest and pytest if they differ)