python-unittest.mock

Mock a series of interdependent calls

久未见 提交于 2019-11-29 13:01:22
I have a method that scrapes a web page and saves data into a file (see below for an example code). I need to test that the resulting data is well-formed. The problem is, the data is received from a series of calls, and further calls use the results of previous ones. What is worse, many of the calls involved are done on the same objects (a Webdriver , a WebDriverWait and the expected_conditions module), with different arguments. I see that unittest.mock.Mock can mock the result of a simple call, or a series of simple calls, but can't see how to implement something entangled like this. The only

Mock a series of interdependent calls

為{幸葍}努か 提交于 2019-11-28 06:44:11
问题 I have a method that scrapes a web page and saves data into a file (see below for an example code). I need to test that the resulting data is well-formed. The problem is, the data is received from a series of calls, and further calls use the results of previous ones. What is worse, many of the calls involved are done on the same objects (a Webdriver , a WebDriverWait and the expected_conditions module), with different arguments. I see that unittest.mock.Mock can mock the result of a simple