How to use command_record_property method in pytest-play

Best Python code snippet using pytest-play_python

test_metrics.py

Source:test_metrics.py Github

copy

Full Screen

...80 provider._record_property = mock_record_property81 provider._record_property_statsd = mock_record_property_statsd82 assert provider.engine is mock_engine83 mock_engine.execute_command.return_value = elapsed*100084 provider.command_record_property({85 'provider': 'metrics',86 'type': 'record_property',87 'name': 'elapsed_milliseconds',88 'expression': 'variables["_elapsed"]*1000',89 })90 assert mock_engine.execute_command.assert_called_once_with(91 {'provider': 'python',92 'type': 'exec',93 'expression': 'variables["_elapsed"]*1000'}) is None94 assert mock_engine \95 .update_variables \96 .assert_called_once_with(97 {'elapsed_milliseconds': elapsed*1000}) is None98 assert mock_record_property \99 .assert_called_once_with(100 'elapsed_milliseconds', elapsed*1000) is None101 assert mock_record_property_statsd \102 .assert_called_once_with(103 'elapsed_milliseconds', elapsed*1000,104 metric_type=None, meas_unit=None) is None105def test_record_property_string_no_statsd():106 import mock107 mock_engine = mock.MagicMock()108 mock_record_property = mock.MagicMock()109 mock_record_property_statsd = mock.MagicMock()110 from pytest_play import providers111 provider = providers.MetricsProvider(mock_engine)112 provider._record_property = mock_record_property113 provider._record_property_statsd = mock_record_property_statsd114 assert provider.engine is mock_engine115 mock_engine.execute_command.return_value = "a string"116 with mock.patch(117 'pytest_play.providers.metrics.MetricsProvider.statsd_client',118 new_callable=mock.PropertyMock) as statsd_client:119 provider.command_record_property({120 'provider': 'metrics',121 'type': 'record_property',122 'name': 'elapsed_milliseconds',123 'expression': '"a string"',124 })125 assert mock_engine.execute_command.assert_called_once_with(126 {'provider': 'python',127 'type': 'exec',128 'expression': '"a string"'}) is None129 assert mock_engine \130 .update_variables \131 .assert_called_once_with(132 {'elapsed_milliseconds': "a string"}) is None133 assert mock_record_property \134 .assert_called_once_with(135 'elapsed_milliseconds', "a string") is None136 assert statsd_client.called is False137def test_record_property_statsd_no_metric_type():138 import mock139 mock_engine = mock.MagicMock()140 elapsed = 0.125141 mock_engine.variables = {'_elapsed': elapsed}142 mock_record_property = mock.MagicMock()143 from pytest_play import providers144 with mock.patch(145 'pytest_play.providers.metrics.MetricsProvider.statsd_client',146 new_callable=mock.PropertyMock) as statsd_client:147 provider = providers.MetricsProvider(mock_engine)148 provider._record_property = mock_record_property149 assert provider.engine is mock_engine150 mock_engine.execute_command.return_value = elapsed*1000151 provider.command_record_property({152 'provider': 'metrics',153 'type': 'record_property',154 'name': 'elapsed_milliseconds',155 'expression': 'variables["_elapsed"]*1000',156 })157 assert mock_engine.execute_command.assert_called_once_with(158 {'provider': 'python',159 'type': 'exec',160 'expression': 'variables["_elapsed"]*1000'}) is None161 assert mock_engine \162 .update_variables \163 .assert_called_once_with(164 {'elapsed_milliseconds': elapsed*1000}) is None165 assert mock_record_property \166 .assert_called_once_with(167 'elapsed_milliseconds', elapsed*1000) is None168 assert statsd_client.return_value.timing.called is False169def test_record_property_statsd_metric_type_timing():170 import mock171 mock_engine = mock.MagicMock()172 elapsed = 0.125173 mock_engine.variables = {'_elapsed': elapsed}174 mock_record_property = mock.MagicMock()175 from pytest_play import providers176 with mock.patch(177 'pytest_play.providers.metrics.MetricsProvider.statsd_client',178 new_callable=mock.PropertyMock) as statsd_client:179 provider = providers.MetricsProvider(mock_engine)180 provider._record_property = mock_record_property181 assert provider.engine is mock_engine182 mock_engine.execute_command.return_value = elapsed*1000183 provider.command_record_property({184 'provider': 'metrics',185 'type': 'record_property',186 'name': 'elapsed_milliseconds',187 'expression': 'variables["_elapsed"]*1000',188 'metric_type': 'timing',189 })190 assert mock_engine.execute_command.assert_called_once_with(191 {'provider': 'python',192 'type': 'exec',193 'expression': 'variables["_elapsed"]*1000'}) is None194 assert mock_engine \195 .update_variables \196 .assert_called_once_with(197 {'elapsed_milliseconds': elapsed*1000}) is None198 assert mock_record_property \199 .assert_called_once_with(200 'elapsed_milliseconds', elapsed*1000) is None201 assert statsd_client.return_value.timing \202 .assert_called_once_with(203 'elapsed_milliseconds', elapsed*1000) is None204@pytest.mark.parametrize("metric_type", ['timing', 'gauge', ])205def test_record_property_statsd_metric_type_negative(metric_type):206 import mock207 mock_engine = mock.MagicMock()208 mock_record_property = mock.MagicMock()209 from pytest_play import providers210 with mock.patch(211 'pytest_play.providers.metrics.MetricsProvider.statsd_client',212 new_callable=mock.PropertyMock) as statsd_client:213 provider = providers.MetricsProvider(mock_engine)214 provider._record_property = mock_record_property215 assert provider.engine is mock_engine216 mock_engine.execute_command.return_value = "a string"217 with pytest.raises(ValueError):218 provider.command_record_property({219 'provider': 'metrics',220 'type': 'record_property',221 'name': 'elapsed_milliseconds',222 'expression': '"a string"',223 'metric_type': metric_type,224 })225 assert mock_engine.execute_command.assert_called_once_with(226 {'provider': 'python',227 'type': 'exec',228 'expression': '"a string"'}) is None229 assert mock_engine \230 .update_variables \231 .called is False232 assert mock_record_property \233 .called is False234 assert statsd_client.return_value.timing \235 .called is False236@pytest.mark.parametrize("metric_type", ['TIMING', ])237def test_record_property_statsd_metric_type_negative_invalid(metric_type):238 import mock239 mock_engine = mock.MagicMock()240 mock_record_property = mock.MagicMock()241 from pytest_play import providers242 with mock.patch(243 'pytest_play.providers.metrics.MetricsProvider.statsd_client',244 new_callable=mock.PropertyMock) as statsd_client:245 provider = providers.MetricsProvider(mock_engine)246 provider._record_property = mock_record_property247 assert provider.engine is mock_engine248 mock_engine.execute_command.return_value = "1"249 with pytest.raises(ValueError):250 provider.command_record_property({251 'provider': 'metrics',252 'type': 'record_property',253 'name': 'elapsed_milliseconds',254 'expression': '"1"',255 'metric_type': metric_type,256 })257 assert mock_engine.execute_command.assert_called_once_with(258 {'provider': 'python',259 'type': 'exec',260 'expression': '"1"'}) is None261 assert mock_engine \262 .update_variables \263 .called is False264 assert mock_record_property \265 .called is False266 assert statsd_client.return_value.timing \267 .called is False268def test_record_property_statsd_metric_type_gauge():269 import mock270 mock_engine = mock.MagicMock()271 elapsed = 0.125272 mock_engine.variables = {'_elapsed': elapsed}273 mock_record_property = mock.MagicMock()274 from pytest_play import providers275 with mock.patch(276 'pytest_play.providers.metrics.MetricsProvider.statsd_client',277 new_callable=mock.PropertyMock) as statsd_client:278 provider = providers.MetricsProvider(mock_engine)279 provider._record_property = mock_record_property280 assert provider.engine is mock_engine281 mock_engine.execute_command.return_value = elapsed*1000282 provider.command_record_property({283 'provider': 'metrics',284 'type': 'record_property',285 'name': 'elapsed_milliseconds',286 'expression': 'variables["_elapsed"]*1000',287 'metric_type': 'gauge',288 })289 assert mock_engine.execute_command.assert_called_once_with(290 {'provider': 'python',291 'type': 'exec',292 'expression': 'variables["_elapsed"]*1000'}) is None293 assert mock_engine \294 .update_variables \295 .assert_called_once_with(296 {'elapsed_milliseconds': elapsed*1000}) is None...

Full Screen

Full Screen

metrics.py

Source:metrics.py Github

copy

Full Screen

...36 """ Record a property metrics """37 self._record_property_statsd(38 name, value, metric_type=metric_type, meas_unit=meas_unit)39 self._record_property(name, value)40 def command_record_property(self, command, **kwargs):41 """ record a property (dynamic expression) """42 name = command['name']43 expression = command['expression']44 metric_type = command.get('metric_type', None)45 value = self.engine.execute_command(46 {'provider': 'python',47 'type': 'exec',48 'expression': expression})49 self.record_property(name, value, metric_type=metric_type)50 self.engine.update_variables({name: value})51 def command_record_elapsed(self, command, **kwargs):52 """ record a property (previous command elapsed) """53 name = command['name']54 value = self.engine.variables['_elapsed']...

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 pytest-play 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