You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I need to go to the page and do some action. But at the same time, I want to mock the foo() function.
If I send a get request through the test client -- everything is OK; but when I open the page in the browser, the code does not mocked. How can I perform some actions on the page with selenium, and at the same time, so that have mock-code?
fromunittestimportmockfromflask_testingimportLiveServerTestCasefromseleniumimportwebdriverdeffoo():
print('\nI am MOCK!!!\n')
classBaseClient(LiveServerTestCase):
defcreate_app(self):
fromviewimportappself.test_client=app.test_client()
returnappdefsetUp(self):
self.browser=webdriver.Firefox()
deftearDown(self):
self.browser.quit()
@classmethoddefget_server_url(cls):
return'http://127.0.0.1:5000'@mock.patch('view.foo', side_effect=foo)deftest_bad_mock(self, mock):
self.browser.get(self.get_server_url()) # will be printed "No mock!", but I want to mock it!@mock.patch('view.foo', side_effect=foo)deftest_correct_mock(self, mock):
self.test_client.get('/') # will be printed "I am MOCK!!!"
The text was updated successfully, but these errors were encountered:
Hello
I have a problem when testing using mock
I need to go to the page and do some action. But at the same time, I want to mock the foo() function.
If I send a get request through the test client -- everything is OK; but when I open the page in the browser, the code does not mocked. How can I perform some actions on the page with selenium, and at the same time, so that have mock-code?
view.py
tests.py
The text was updated successfully, but these errors were encountered: