Best Python code snippet using autotest_python
database_connection_unittest.py
Source:database_connection_unittest.py  
...61        self._fake_backend.disconnect.expect_call()62        call = self._fake_backend.connect.expect_call(**_CONNECT_KWARGS)63        if fail:64            call.and_raises(FakeDatabaseError())65    def _expect_fail_and_reconnect(self, num_reconnects, fail_last=False):66        self._fake_backend.connect.expect_call(**_CONNECT_KWARGS).and_raises(67            FakeDatabaseError())68        for i in xrange(num_reconnects):69            time.sleep.expect_call(_RECONNECT_DELAY)70            if i < num_reconnects - 1:71                self._expect_reconnect(fail=True)72            else:73                self._expect_reconnect(fail=fail_last)74    def test_connect_retry(self):75        db = self._get_database_connection()76        self._expect_fail_and_reconnect(1)77        db.connect()78        self.god.check_playback()79        self._fake_backend.disconnect.expect_call()80        self._expect_fail_and_reconnect(0)81        self.assertRaises(FakeDatabaseError, db.connect,82                          try_reconnecting=False)83        self.god.check_playback()84        db.reconnect_enabled = False85        self._fake_backend.disconnect.expect_call()86        self._expect_fail_and_reconnect(0)87        self.assertRaises(FakeDatabaseError, db.connect)88        self.god.check_playback()89    def test_max_reconnect(self):90        db = self._get_database_connection()91        db.max_reconnect_attempts = 592        self._expect_fail_and_reconnect(5, fail_last=True)93        self.assertRaises(FakeDatabaseError, db.connect)94        self.god.check_playback()95    def test_reconnect_forever(self):96        db = self._get_database_connection()97        db.max_reconnect_attempts = database_connection.RECONNECT_FOREVER98        self._expect_fail_and_reconnect(30)99        db.connect()100        self.god.check_playback()101    def _simple_connect(self, db):102        self._fake_backend.connect.expect_call(**_CONNECT_KWARGS)103        db.connect()104        self.god.check_playback()105    def test_disconnect(self):106        db = self._get_database_connection()107        self._simple_connect(db)108        self._fake_backend.disconnect.expect_call()109        db.disconnect()110        self.god.check_playback()111    def test_execute(self):112        db = self._get_database_connection()...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!!
