How to use make_decorator method in Nose

Best Python code snippet using nose

test_decorators.py

Source:test_decorators.py Github

copy

Full Screen

...183 # performed in the above order for each decorator, but we should184 # iterate through the decorators in the reverse of the order they185 # appear in the source.186 actions = []187 def make_decorator(tag):188 actions.append('makedec' + tag)189 def decorate(func):190 actions.append('calldec' + tag)191 return func192 return decorate193 class NameLookupTracer (object):194 def __init__(self, index):195 self.index = index196 def __getattr__(self, fname):197 if fname == 'make_decorator':198 opname, res = ('evalname', make_decorator)199 elif fname == 'arg':200 opname, res = ('evalargs', str(self.index))201 else:202 assert False, "Unknown attrname %s" % fname203 actions.append('%s%d' % (opname, self.index))204 return res205 c1, c2, c3 = map(NameLookupTracer, [ 1, 2, 3 ])206 expected_actions = [ 'evalname1', 'evalargs1', 'makedec1',207 'evalname2', 'evalargs2', 'makedec2',208 'evalname3', 'evalargs3', 'makedec3',209 'calldec3', 'calldec2', 'calldec1' ]210 actions = []211 @c1.make_decorator(c1.arg)212 @c2.make_decorator(c2.arg)213 @c3.make_decorator(c3.arg)214 def foo(): return 42215 self.assertEqual(foo(), 42)216 self.assertEqual(actions, expected_actions)217 # Test the equivalence claim in chapter 7 of the reference manual.218 #219 actions = []220 def bar(): return 42221 bar = c1.make_decorator(c1.arg)(c2.make_decorator(c2.arg)(c3.make_decorator(c3.arg)(bar)))222 self.assertEqual(bar(), 42)223 self.assertEqual(actions, expected_actions)224class TestClassDecorators(unittest.TestCase):225 def test_simple(self):226 def plain(x):227 x.extra = 'Hello'228 return x229 @plain230 class C(object): pass231 self.assertEqual(C.extra, 'Hello')232 def test_double(self):233 def ten(x):234 x.extra = 10235 return x...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Nose automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful