Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/sync_buckets/sync_buckets.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Copy objects from one S3 bucket to another."""

import optparse

import boto3
Expand Down
1 change: 1 addition & 0 deletions examples/sync_buckets/test_sync_buckets.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test sync_buckets.py"""

import boto3
from sync_buckets import sync_buckets

Expand Down
1,834 changes: 868 additions & 966 deletions poetry.lock

Large diffs are not rendered by default.

35 changes: 17 additions & 18 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pytest-localstack"
version = "0.6.1"
version = "0.6.1.post8"
description = "Pytest plugin for AWS integration tests"
authors = ["Mintel Group Ltd."]
license = "MIT"
Expand Down Expand Up @@ -30,26 +30,25 @@ include = ["CHANGELOG.rst", "LICENSE"]
localstack = "pytest_localstack"

[tool.poetry.dependencies]
python = "^3.7.0"
python = "^3.9.0"
botocore = "!=1.4.45"
urllib3 = "<2" # https://github.com/orgs/python-poetry/discussions/7937#discussioncomment-5921842
docker = "^6.0.0"
pluggy = "^0.12.0"
pytest = "^6.0.0" # need caplog (+ warnings for tests)
docker = ">=6.0.0"
pluggy = "^1.0.0"
pytest = ">=6.0.0" # need caplog (+ warnings for tests)

[tool.poetry.dev-dependencies]
boto3 = "*"
hypothesis = "*"
black = "*"
isort = "^5.8.0"
mypy = "^0.812"
flake8 = "^3.9.2"
bandit = "^1.7.0"
pyproject-flake8 = "^0.0.1-alpha.2"
coverage = {extras = ["toml"], version = "^5.5"}
codecov = "^2.1.11"
pytest-cov = "^2.12.1"
pytest-xdist = "^2.2.1"
boto3 = "^1.40.0"
hypothesis = "^6.138.0"
black = ">=25.0"
isort = ">=6.0"
mypy = ">=1.18"
flake8 = ">=6.0"
bandit = ">=1.7"
pyproject-flake8 = ">=6.0"
coverage = {extras = ["toml"], version = ">=7.10"}
codecov = ">=2.1"
pytest-cov = ">=6.0"
pytest-xdist = ">=3.8"
Sphinx = "^4.0.2"

[build-system]
Expand Down
1 change: 1 addition & 0 deletions pytest_localstack/container.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Docker container tools."""

import threading

from pytest_localstack import utils
Expand Down
1 change: 1 addition & 0 deletions pytest_localstack/contrib/boto3.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""pytest-localstack extensions for boto3."""

import logging

import boto3.session
Expand Down
5 changes: 4 additions & 1 deletion pytest_localstack/contrib/botocore.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test resource factory for the botocore library."""

import contextlib
import functools
import inspect
Expand Down Expand Up @@ -456,7 +457,9 @@ def create_client(self, *args, **kwargs):
"""Create a botocore client."""
# Localstack doesn't use the virtual host addressing style.
config = botocore.config.Config(s3={"addressing_style": "path"})
callargs = inspect.getcallargs(_original_create_client, self, *args, **kwargs)
callargs = inspect.getcallargs(
inspect.unwrap(_original_create_client), self, *args, **kwargs
)
if callargs.get("config"):
config = callargs["config"].merge(config)
callargs["config"] = config
Expand Down
1 change: 1 addition & 0 deletions pytest_localstack/hookspecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Localstack container is started and stopped.

"""

import pluggy


Expand Down
1 change: 1 addition & 0 deletions pytest_localstack/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.. seealso:: :mod:`~pytest_localstack.hookspecs`

"""

import importlib

import pluggy
Expand Down
1 change: 1 addition & 0 deletions pytest_localstack/service_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
raises :class:`~pytest_localstack.exceptions.ServiceError`
if the service is not available.
"""

import contextlib
import functools
import socket
Expand Down
34 changes: 33 additions & 1 deletion pytest_localstack/session.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
"""Run and interact with a Localstack container."""

import logging
import os
import re
import string
import threading
import time
from copy import copy
from keyword import kwlist

from docker.types import Mount

from pytest_localstack import (
constants,
Expand Down Expand Up @@ -248,6 +252,10 @@ def __init__(
container_name=None,
use_ssl=False,
hostname=None,
privileged=False,
mount_docker_socket=False,
docker_socket="/var/run/docker.sock",
additional_env=None,
**kwargs,
):
self._container = None
Expand All @@ -260,6 +268,10 @@ def __init__(
self.dynamodb_error_probability = dynamodb_error_probability
self.auto_remove = bool(auto_remove)
self.pull_image = bool(pull_image)
self.docker_socket = docker_socket
self.mount_docker_socket = bool(mount_docker_socket)
self.additional_env = (additional_env or {}).copy()
self.privileged = bool(privileged)

super(LocalstackSession, self).__init__(
hostname=hostname if hostname else default_hostname(),
Expand Down Expand Up @@ -307,19 +319,39 @@ def start(self, timeout=60):
kinesis_error_probability = "%f" % self.kinesis_error_probability
dynamodb_error_probability = "%f" % self.dynamodb_error_probability
use_ssl = str(self.use_ssl).lower()

mounts = []
if self.mount_docker_socket and self.docker_socket:
# required for lambda v2 but optional because some
# environments don't allow mounting the docker socket
# or not requiring it (e.g. when not using lambda)
mount = Mount(
target="/var/run/docker.sock",
source=self.docker_socket,
type="bind",
)
mounts.append(mount)

if self.region_name:
# Default region is deprecated, but some tests
# may still rely on it or in older container versions
self.additional_env["DEFAULT_REGION"] = self.region_name

self._container = self.docker_client.containers.run(
image_name,
name=self.container_name,
detach=True,
auto_remove=self.auto_remove,
environment={
"DEFAULT_REGION": self.region_name,
"SERVICES": services,
"KINESIS_ERROR_PROBABILITY": kinesis_error_probability,
"DYNAMODB_ERROR_PROBABILITY": dynamodb_error_probability,
"USE_SSL": use_ssl,
**self.additional_env,
},
privileged=self.privileged,
ports={port: None for port in self.services.values()},
mounts=mounts,
)
logger.debug(
"Started Localstack container %s (id: %s)",
Expand Down
1 change: 1 addition & 0 deletions pytest_localstack/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Misc utilities."""

import contextlib
import os
import types
Expand Down
1 change: 1 addition & 0 deletions tests/functional/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Configure pytest for the functional tests module."""

import docker

import pytest
Expand Down
1 change: 1 addition & 0 deletions tests/functional/test_container.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Functional tests for pytest_localstack.container."""

import logging

from pytest_localstack import container
Expand Down
1 change: 1 addition & 0 deletions tests/functional/test_patch_fixture/test_README.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test examples from the README."""

import boto3

import pytest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test all services accessible for pytest_localstack.patch_fixture."""

import boto3
import botocore

Expand Down
1 change: 1 addition & 0 deletions tests/functional/test_service_fixture/test_README.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test examples from the README."""

import pytest_localstack


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test all services accessible for pytest_localstack.session_fixture."""

import pytest_localstack


Expand Down
1 change: 1 addition & 0 deletions tests/functional/test_session.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Functional tests for pytest_localstack.session."""

import pytest

from pytest_localstack import constants, exceptions, service_checks, session
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Unit tests for pytest_localstack.utils."""

import os
from unittest import mock

Expand Down
1 change: 1 addition & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test utils."""

import hashlib
from unittest import mock

Expand Down