Mocking a global variable

后端 未结 4 1234
执念已碎
执念已碎 2020-12-24 11:27

I\'ve been trying to implement some unit tests for a module. An example module named alphabet.py is as follows:

import database

def length_letters(         


        
4条回答
  •  攒了一身酷
    2020-12-24 11:46

    You don't need to use mock. Just import the module and alter the value of the global within setUp():

    import alphabet
    
    class TestAlphabet(unittest.TestCase): 
       def setUp(self):
            alphabet.letters = ['a', 'b', 'c']
    

提交回复
热议问题