Sunday, 15 April 2012

python 2.7 - mocking sleep in a test -


I have a function to test that eventually calls the second function in which there is some time. If I do not want my trial to sleep, my question is, is it better to duplicate the test function, or is it better to wrap your call in the function to test from the patch?

Example 1

  @patch 'Time.sleep') Def test_some_function (mock_time): data = some_sleepy_function () insert data == expected_data   

Example 2:

  def test_some_function (): @patch ('time sol') DRF run_function (mc_sd): run back_s leepy_function () _ work () == I like the  monkeypatch of py.test to make something simple like expected_data    

unittest Test seas subclasses).

/ html>

No comments:

Post a Comment