How to use proxied_attribute method in Nose

Best Python code snippet using nose

proxy.py

Source:proxy.py Github

copy

Full Screen

...15"""16import logging17from nose.config import Config18log = logging.getLogger(__name__)19def proxied_attribute(local_attr, proxied_attr, doc):20 """Create a property that proxies attribute ``proxied_attr`` through21 the local attribute ``local_attr``.22 """23 def fget(self):24 return getattr(getattr(self, local_attr), proxied_attr)25 def fset(self, value):26 setattr(getattr(self, local_attr), proxied_attr, value)27 def fdel(self):28 delattr(getattr(self, local_attr), proxied_attr)29 return property(fget, fset, fdel, doc)30class ResultProxyFactory(object):31 """Factory for result proxies. Generates a ResultProxy bound to each test32 and the result passed to the test.33 """34 def __init__(self, config=None):35 if config is None:36 config = Config()37 self.config = config38 self.__prepared = False39 self.__result = None40 def __call__(self, result, test):41 """Return a ResultProxy for the current test.42 On first call, plugins are given a chance to replace the43 result used for the remaining tests. If a plugin returns a44 value from prepareTestResult, that object will be used as the45 result for all tests.46 """47 if not self.__prepared:48 self.__prepared = True49 plug_result = self.config.plugins.prepareTestResult(result)50 if plug_result is not None:51 self.__result = result = plug_result52 if self.__result is not None:53 result = self.__result54 return ResultProxy(result, test, config=self.config)55class ResultProxy(object):56 """Proxy to TestResults (or other results handler).57 One ResultProxy is created for each nose.case.Test. The result58 proxy calls plugins with the nose.case.Test instance (instead of59 the wrapped test case) as each result call is made. Finally, the60 real result method is called, also with the nose.case.Test61 instance as the test parameter.62 63 """ 64 def __init__(self, result, test, config=None):65 if config is None:66 config = Config()67 self.config = config68 self.plugins = config.plugins69 self.result = result70 self.test = test71 def __repr__(self):72 return repr(self.result)73 def assertMyTest(self, test):74 # The test I was called with must be my .test or my75 # .test's .test. or my .test.test's .case76 case = getattr(self.test, 'test', None)77 assert (test is self.test 78 or test is case 79 or test is getattr(case, '_nose_case', None), 80 "ResultProxy for %r (%s) was called with test %r (%s)" 81 % (self.test, id(self.test), test, id(test)))82 83 def afterTest(self, test):84 self.assertMyTest(test)85 self.plugins.afterTest(self.test)86 if hasattr(self.result, "afterTest"):87 self.result.afterTest(self.test)88 def beforeTest(self, test):89 self.assertMyTest(test)90 self.plugins.beforeTest(self.test)91 if hasattr(self.result, "beforeTest"):92 self.result.beforeTest(self.test)93 def addError(self, test, err):94 self.assertMyTest(test)95 plugins = self.plugins96 plugin_handled = plugins.handleError(self.test, err)97 if plugin_handled:98 return99 formatted = plugins.formatError(self.test, err)100 if formatted is not None:101 err = formatted102 plugins.addError(self.test, err)103 self.result.addError(self.test, err)104 if not self.result.wasSuccessful() and self.config.stopOnError:105 self.shouldStop = True106 def addFailure(self, test, err):107 self.assertMyTest(test)108 plugins = self.plugins109 plugin_handled = plugins.handleFailure(self.test, err)110 if plugin_handled:111 return112 formatted = plugins.formatFailure(self.test, err)113 if formatted is not None:114 err = formatted115 plugins.addFailure(self.test, err)116 self.result.addFailure(self.test, err)117 if self.config.stopOnError:118 self.shouldStop = True119 120 def addSuccess(self, test):121 self.assertMyTest(test)122 self.plugins.addSuccess(self.test)123 self.result.addSuccess(self.test)124 def startTest(self, test):125 self.assertMyTest(test)126 self.plugins.startTest(self.test)127 self.result.startTest(self.test)128 129 def stop(self):130 self.result.stop()131 132 def stopTest(self, test):133 self.assertMyTest(test)134 self.plugins.stopTest(self.test)135 self.result.stopTest(self.test)136 # proxied attributes137 shouldStop = proxied_attribute('result', 'shouldStop',138 """Should the test run stop?""")139 errors = proxied_attribute('result', 'errors',140 """Tests that raised an exception""")141 failures = proxied_attribute('result', 'failures',142 """Tests that failed""")143 testsRun = proxied_attribute('result', 'testsRun',...

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