Best Python code snippet using nose
proxy.py
Source: proxy.py
...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',...
Check out the latest blogs from LambdaTest on this topic:
If you are wondering why your Javascript application might be suffering from severe slowdowns, poor performance, high latency or frequent crashes and all your painstaking attempts to figure out the problem were to no avail, there is a pretty good chance that your code is plagued by ‘Memory Leaks’. Memory leaks are fairly common as memory management is often neglected by developers due to the misconceptions about automatic memory allocation and release in modern high level programming languages like javascript. Failure to deal with javascript memory leaks can wreak havoc on your app’s performance and can render it unusable. The Internet is flooded with never-ending complex jargon which is often difficult to wrap your head around. So in this article, we will take a comprehensive approach to understand what javascript memory leaks are, its causes and how to spot and diagnose them easily using chrome developer tools.
This article is a part of our Content Hub. For more in-depth resources, check out our content hub on Top CI/CD Tools Comparison.
He is a gifted driver. Famed for speed, reverse J, and drifts. He can breeze through the Moscow and Mexico traffic without sweating a drop. Of course, no one gets cracking on Bengaluru roads ???? But despite being so adept behind the wheels, he sometimes fails to champ the street races. Screeching tyres buzz in his head doesn’t let him sleep at times. I wish to tell him it’s not always about the driver, sometimes it’s the engine. That’s what happens when the right dev talent uses wrong, inefficient, incompatible CI/CD tools. The DevOps technologies you chose can abruptly break or smoothly accelerate your software development cycle. This article explores the Ford & the Ferrari of the CI/CD world in detail, CircleCI vs. GitLab, to help you pick the right one.
This article is a part of our Content Hub. For more in-depth resources, check out our content hub on Selenium 4 and Selenium Python Tutorial
It has been around a year since we went live with the first iteration of LambdaTest Platform. We started off our product offering manual cross browser testing solutions and kept expanding our platform. We were asked many feature requests, and we implemented quite a lot of them. However, the biggest demand was to bring automation testing to the platform. Today we deliver on this feature.
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!