Unit Test Behavior with correction (flask)

I am trying to use methods patchin my api bulb, but it seems that the method call is not replaced. Does app.test_client()something under the hood that I miss.

For example, if I run

 @patch('k.stats.mstats')
  def test_ps(self, mstats):
    mstats.return_value = (1, 2, 3)
    rv = self.app.get('/ps/')

and I go through the debugger to the point below:

@app.route('/ps/', methods=['GET'])
def ps():
  import pdb
  pdb.set_trace()
  mstats()

and by checking mstats, I will return the function that will be removed.

However, if I run from k.stats import mstatsthe breakpoint, I return the bullying method that I am looking for.

How to ensure that the called method is called?

+4
source share
1 answer

This is a rather confusing concept, but the documentation ispatch trying to explain it.

Patch

(), , . , , , , .

, , , .

, ; , .

, , .

, mstats stats. from stats import mstats use_stats.

use_stats, .

@patch('use_stats.mstats')
def test_stats(self, mstats):
    pass
+2

Source: https://habr.com/ru/post/1584364/


All Articles