Best Python code snippet using pytest-benchmark
test_decorators.py
Source:test_decorators.py
...71 def test_bad(data: typing.Any) -> int:72 return data73 @staticmethod74 @runtime_validation75 def test_bad2(data: typing.Any) -> int:76 return data77 sample = SampleClass()78 self.assertEqual(sample.test(1), 1)79 self.assertEqual(sample.test2(1), 1)80 self.assertEqual(sample.test_bad(1), 1)81 self.assertEqual(sample.test_bad2(1), 1)82 self.assertEqual(SampleClass.test(1), 1)83 self.assertEqual(SampleClass.test2(1), 1)84 self.assertEqual(SampleClass.test_bad(1), 1)85 self.assertEqual(SampleClass.test_bad2(1), 1)86 with self.assertRaises(RuntimeTypeError):87 sample.test('')88 with self.assertRaises(RuntimeTypeError):89 sample.test2('')90 with self.assertRaises(RuntimeTypeError):91 sample.test_bad('')92 with self.assertRaises(RuntimeTypeError):93 sample.test_bad2('')94 with self.assertRaises(RuntimeTypeError):95 SampleClass.test('')96 with self.assertRaises(RuntimeTypeError):97 SampleClass.test2('')98 with self.assertRaises(RuntimeTypeError):99 SampleClass.test_bad('')100 with self.assertRaises(RuntimeTypeError):101 SampleClass.test_bad2('')102 def test_classmethod(self):103 """104 Checks if a classmethod of a class object can be decorated105 """106 class SampleClass:107 @runtime_validation108 @classmethod109 def test(cls, data: int) -> int:110 return data111 @classmethod112 @runtime_validation113 def test2(cls, data: int) -> int:114 return data115 @runtime_validation116 @classmethod117 def test_bad(cls, data: typing.Any) -> int:118 return data119 @classmethod120 @runtime_validation121 def test_bad2(cls, data: typing.Any) -> int:122 return data123 sample = SampleClass()124 self.assertEqual(sample.test(1), 1)125 self.assertEqual(sample.test2(1), 1)126 self.assertEqual(sample.test_bad(1), 1)127 self.assertEqual(sample.test_bad2(1), 1)128 self.assertEqual(SampleClass.test(1), 1)129 self.assertEqual(SampleClass.test2(1), 1)130 self.assertEqual(SampleClass.test_bad(1), 1)131 self.assertEqual(SampleClass.test_bad2(1), 1)132 #with self.assertRaises(RuntimeTypeError):133 # sample.test('')134 with self.assertRaises(RuntimeTypeError):135 sample.test2('')136 #with self.assertRaises(RuntimeTypeError):137 # sample.test_bad('')138 with self.assertRaises(RuntimeTypeError):139 sample.test_bad2('')140 #with self.assertRaises(RuntimeTypeError):141 # SampleClass.test('')142 with self.assertRaises(RuntimeTypeError):143 SampleClass.test2('')144 #with self.assertRaises(RuntimeTypeError):145 # SampleClass.test_bad('')146 with self.assertRaises(RuntimeTypeError):147 SampleClass.test_bad2('')148 def test_property(self):149 """150 Checks if property object can be type checked151 """152 @runtime_validation153 class Sample:154 def __init__(self):155 self._x = 0156 @property157 def x(self):158 return self._x159 @x.setter160 def x(self, value: int):161 self._x = value...
test_integr.py
Source:test_integr.py
...8def test_bad1():9 with pytest.raises(ValueError):10 parse("bad input")11@pytest.mark.xfail(raises=ValueError)12def test_bad2():...
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!!