unit testing - Python mock: mock object not updated when running multiple tests -


I'm trying to duplicate a function calling a remote_pia:

  Def get_remote_value (): Ret = make_distant_call () Return Rate & gt; 0  

This function is said in another function:

  import_remote_value def_remote_value (): remote_value = get_remote_value () # actually calculates some This does not return the problem.  

This is my test:

  @ mock.patch ('another_file.get_remote_value') class MyTest ( TestCase): Def first_test (self, mock_get_remote_value): mock_get_remote_value.return_value = true self.assertEqual (check_remote_value (), True) def second_test (self, mock_get_remote_value): mock_get_remote_value.return_value = wrong self.assertEqual (check_remote_value (), False) / Code>  

When I test every If I run into the exam, then it works fine. When I run the entire class, the second test fails because get_remote_value returns true and false not.

I think check_remote_value function is still using the old fake and that's what's causing the problem am i right? Anyway, how can I change my test so that it runs smoothly?

I tried to use decorator for each function using the patch reference manager, it has no advantage. The funny of the whole check_remote_value is not really an option because it's the one I want to test.

you that the name needs to patch Chek_prkash_man the Uses.

  @ mock.path ( 'mymodule.utils.another_file.get_remote_value') class MyTest (Test Seas): def first_test (self, mock_get_remote_value): mock_get_remote_value.return_value = true self.assertEqual (Chek_ remote_value (), True) def second_test (self, mock_get_remote_value): mock_get_remote_value.return_value = False is self.assertEqual (check_remote_value (), False)  

how it functions, global values ​​shows. check_remote_value is not mymodule.utils a reference to define global scope, not your test script, so it seems that when it get_remote_value .


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -