lundi 25 juin 2018

python patch mock are shared by tests

I'm trying to test my code, and I'm using patch

this is my code:

def test_not_authorized(self):
    with patch('dontacare.has_access', return_value=False):
        res = Auth.fetch()

def test_authorized(self):
    with patch('dontacare.has_access', return_value=True):
        res = Auth.fetch()

the problem is that if I add the second test, so the first test has_access function now returns True instead of False.

Why do different tests impact each other??

Thanks!

Aucun commentaire:

Enregistrer un commentaire