How to use test_run_fail method in avocado

Best Python code snippet using avocado_python

test_nmea.py

Source:test_nmea.py Github

copy

Full Screen

...12class TestStartCanBus(unittest.TestCase):13 """Test cases for start_can_bus."""14 @patch('subprocess.run', return_value=0,15 side_effect=subprocess.CalledProcessError(256, 'ip'))16 def test_run_fail(self, ip_call):17 """start_can_bus() ip link set fails"""18 with self.assertLogs(level='ERROR') as logs:19 bus = nmea.start_can_bus()20 ip_call.assert_called_with('sudo ip link set can0 type can '21 'bitrate 100000', check=True)22 self.assertEqual(logs.output,23 ['ERROR:nmea:ip link set can0: FAIL',24 'ERROR:nmea:return code = 256'],25 msg='expect ERROR logged when ip link set fails.')26 self.assertIsNone(bus, msg='start_can_bus should return None if '27 'call to ip link set fails.')28 @patch('subprocess.run')29 def test_run2_fail(self, ip_call):30 """start_can_bus() ifconfig fails"""31 def subprocess_call_behaviour(*args, **kwargs):32 if args[0] == 'sudo ip link set can0 type can bitrate 100000':33 return 034 raise subprocess.CalledProcessError(256, 'ip')35 ip_call.side_effect = subprocess_call_behaviour36 with self.assertLogs(level='ERROR') as logs:37 bus = nmea.start_can_bus()38 self.assertEqual(logs.output,39 ['ERROR:nmea:ifconfig can0 up: FAIL',40 'ERROR:nmea:return code = 256'],41 msg='expect ERROR logged when ip link set fails.')42 self.assertIsNone(bus, msg='start_can_bus should return None if '43 'call to ifconfig fails.')44 @patch('subprocess.run', return_value=0)45 @patch('can.interface.Bus')46 def test_sucessful_start(self, can_bus, ip_call):47 """start_can_bus() sucess."""48 bus = nmea.start_can_bus()49 expected_ip_calls = [call('sudo ip link set can0 type can bitrate '50 '100000', check=True),51 call('sudo ifconfig can0 up', check=True)]52 self.assertEqual(ip_call.call_args_list, expected_ip_calls,53 msg='Expected two successful subprocess calls.')54 self.assertEqual(can_bus.call_args_list,55 [call(channel='can0', bustype='socketcan_ctypes')],56 msg='Expected one successful call to create'57 'can.interface.bus')58 self.assertIsNotNone(bus,59 msg='start_can_bus should return a Bus object'60 'when called successfully')61class TestStopCanBus(unittest.TestCase):62 """Test cases for stop_can_bus."""63 @patch('subprocess.run', return_value=0,64 side_effect=subprocess.CalledProcessError(256, 'ip'))65 def test_run_fail(self, ip_call):66 """stop_can_bus() ifconfig fails"""67 with self.assertLogs(level='ERROR') as logs:68 rc = nmea.stop_can_bus()69 rc = nmea.stop_can_bus()70 ip_call.assert_called_with('sudo ifconfig can0 down', check=True)71 print(logs.output)72# self.assertEqual(logs.output,73# ['ERROR:nmea:ifconfig can0 up: FAIL',74# 'ERROR:nmea:return code = 256'],75# msg='expect ERROR logged when ip link set fails.')76 self.assertIsNone(rc, msg='stop_can_bus should return None if call to'77 'ifconfig fails.')78 @patch('subprocess.run', return_value=0)79 def test_successful_stop(self, ip_call):...

Full Screen

Full Screen

test_util.py

Source:test_util.py Github

copy

Full Screen

1from virtualenv.util.subprocess import run_cmd2def test_run_fail(tmp_path):3 code, out, err = run_cmd([str(tmp_path)])4 assert err5 assert not out...

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 avocado 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