python - Apply a single decorator to multiple functions -


i've searched this, results i've seen involve opposite: applying multiple decorators single function.

i'd simplify pattern. there way apply single decorator multiple functions? if not, how can rewrite above less repetitious?

from mock import patch  @patch('somelongmodulename.somelongmodulefunction') def test_a(patched):     pass  # test 1 behavior using above function  @patch('somelongmodulename.somelongmodulefunction') def test_b(patched):     pass  # test behavior  @patch('somelongmodulename.somelongmodulefunction') def test_c(patched):     pass  # test third behavior 
from mock import patch  patched_name = 'somelongmodulename.somelongmodulefunction'  @patch(patched_name) def test_a(patched):     pass  # test 1 behavior using above function  @patch(patched_name) def test_b(patched):     pass  # test behavior  @patch(patched_name) def test_c(patched):     pass  # test third behavior 

if want make "long" function call once , decorate 3 functions result, that.

my_patch = patch('somelongmodulename.somelongmodulefunction')  @my_patch def test_a(patched):     pass  @my_patch def test_b(patched):     pass 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -