Category : pytest

I am trying to test if a newly created table has continuous backups enabled. I am using Python and pytest as follows: client = boto3.client(‘dynamodb’, environ[‘REGION’]) backup_status = client.describe_continuous_backups(TableName=logs_table_name)[‘ContinuousBackupDescription’][‘PointInTimeRecoveryDescription’][‘PointInTimeRecoveryStatus’] assert backup_status == ‘ENABLED’ When the test runs it returns below error @amzn_request_id def call_action(self): self.body = json.loads(self.body or "{}") endpoint = self.get_endpoint_name(self.headers) if endpoint: endpoint ..

Read more

I’m using Python 3.8. I have a class with a member field … class AbcServiceBus: def __init__(self, …): … self._service_bus = AzureServiceBus()     def send_insert_notification(self, record_id):         message_json = {‘ids’: [record_id]}          self._service_bus.send_topic_message(             namespace_name=self._namespace,             topic_name=self._topic_name,              message_json=message_json         )           return True I would like to mock the "send_topic_message" method of the member field. I tried the below from unittest import mock …     sb = AbcServiceBus(device)     with mock.patch(‘common.azure_service_bus.AzureServiceBus.send_topic_message’) as send_topic_message_mock:         sb.send_insert_notification(record_id)         send_topic_message_mock.assert_called_with(             sb._namespace,              sb._topic_name,              {‘ids’: [record_id]}         ) but this continues ..

Read more

I have a config file where I keep the connection string for my database config.py POSTGRES_USER = os.getenv(‘POSTGRES_USER’) POSTGRES_PASSWORD = os.getenv(‘POSTGRES_PASSWORD’) POSTGRES_DB = os.getenv(‘POSTGRES_DB’) POSTGRES_HOST = os.getenv(‘POSTGRES_HOST’) conn_url = f"postgresql+psycopg2://{POSTGRES_USER}:{POSTGRES_PASSWORD}@{POSTGRES_HOST}/{POSTGRES_DB}" engine = create_engine(conn_url, echo=False) Session = sessionmaker(bind=engine) Base = declarative_base() And when I need to use the session I’d do this from database.config import Session ..

Read more

I have been using pytest-mock library for mocking with pytest. When I’m trying to run the test using tox command, I am getting the following error: … tests/test_cli.py ….EEEE … file /path/to/test_cli.py, line 63 def test_cli_with_init_cmd_fails_with_db_error(runner, mocker, context): E fixture ‘mocker’ not found > available fixtures: cache, capfd, capfdbinary, caplog, capsys, capsysbinary, context, cov, doctest_namespace, ..

Read more