Best Python code snippet using localstack_python
test_error_injection.py
Source:test_error_injection.py
...58 config.DYNAMODB_READ_ERROR_PROBABILITY = 1.059 assert_raises(ClientError, table.get_item, Key={PARTITION_KEY: partition_key})60 # reset probability to zero61 config.DYNAMODB_READ_ERROR_PROBABILITY = 0.062def test_dynamodb_write_error_injection():63 if not do_run():64 return65 table = get_dynamodb_table()66 # by default, no errors67 test_no_errors = table.put_item(Item={PARTITION_KEY: short_uid(), 'data': 'foobar123'})68 assert_equal(test_no_errors['ResponseMetadata']['HTTPStatusCode'], 200)69 # with a probability of 1, always throw errors70 config.DYNAMODB_WRITE_ERROR_PROBABILITY = 1.071 assert_raises(ClientError, table.put_item, Item={PARTITION_KEY: short_uid(), 'data': 'foobar123'})72 # reset probability to zero73 config.DYNAMODB_WRITE_ERROR_PROBABILITY = 0.074def do_run():75 # Only run the tests if the $TEST_ERROR_INJECTION environment variable is set. This is to reduce the76 # testing time, because the injected errors result in retries and timeouts that slow down the tests overall....
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!!