Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Poprawne sprzątanie po patchowaniu funkcji za pomocą modułu mock w TestCase.setUp() #4

Open
dybi opened this issue May 10, 2018 · 2 comments

Comments

@dybi
Copy link

dybi commented May 10, 2018

Actually there is one pitfall patching this way. If for some reasonsetUp fails, tearDown method will not be called for it, thus patch will remian 'unstopped'. To overcame this, you could rewrite the setup to sth like:

def setUp(self):
        super().setUp()
        patcher_in_message_handlers = mock.patch('core.message_handlers.calculate_subtask_verification_time', return_value=1800)
        patcher_in_transfer_operations = mock.patch('core.transfer_operations.calculate_subtask_verification_time', return_value=1800)
        self.addCleanup(patcher_in_message_handlers.stop)
        self.addCleanup(patcher_in_transfer_operations.stop)
        patcher_in_message_handlers.start()
        patcher_in_transfer_operations.start()
@cameel cameel changed the title Dodać wpisy w "python coding style" odnośnie patching pitfalls Poprawne sprzątanie po patchowaniu funkcji za pomocą modułu mock w TestCase.setUp() May 10, 2018
@rwrzesien
Copy link

👍

@cameel
Copy link
Member

cameel commented Jun 13, 2018

@dybi @rwrzesien Moglibyście podać konkretny tekst jaki powinien trafić do Coding Style?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants