Skip to content

Commit 51ea440

Browse files
committed
fix: use xdist
1 parent 02bc30b commit 51ea440

19 files changed

+61
-66
lines changed

parallel_run_e2e.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def main():
88
features = Path("tests/e2e").rglob("infrastructure.py")
99
workers = len(list(features)) - 1
1010

11-
command = f"poetry run pytest -n {workers} --dist loadfile -o log_cli=true tests/e2e"
11+
command = f"poetry run pytest -n {workers} --dist loadgroup -o log_cli=true tests/e2e"
1212
result = subprocess.run(command.split(), shell=False)
1313
sys.exit(result.returncode)
1414

tests/e2e/conftest.py

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ def lambda_layer_build(tmp_path_factory: pytest.TempPathFactory, worker_id: str)
2323

2424
layer = LocalLambdaPowertoolsLayer()
2525
yield from call_once(
26-
job_id="lambda_layer",
2726
task=layer.build,
2827
tmp_path_factory=tmp_path_factory,
2928
worker_id=worker_id,

tests/e2e/event_handler/conftest.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import pytest
22

33
from tests.e2e.event_handler.infrastructure import EventHandlerStack
4-
from tests.e2e.utils.infrastructure import call_once
54

65

7-
@pytest.fixture(autouse=True, scope="module")
8-
def infrastructure(tmp_path_factory: pytest.TempPathFactory, worker_id: str):
6+
@pytest.fixture(autouse=True, scope="package")
7+
def infrastructure():
98
"""Setup and teardown logic for E2E test infrastructure
109
1110
Yields
@@ -15,10 +14,6 @@ def infrastructure(tmp_path_factory: pytest.TempPathFactory, worker_id: str):
1514
"""
1615
stack = EventHandlerStack()
1716
try:
18-
return (
19-
yield from call_once(
20-
job_id=stack.feature_name, task=stack.deploy, tmp_path_factory=tmp_path_factory, worker_id=worker_id
21-
)
22-
)
17+
yield stack.deploy()
2318
finally:
2419
stack.delete()

tests/e2e/event_handler/test_header_serializer.py

+5
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def lambda_function_url_endpoint(infrastructure: dict) -> str:
3636
return infrastructure.get("LambdaFunctionUrl", "")
3737

3838

39+
@pytest.mark.xdist_group(name="event_handler")
3940
def test_alb_headers_serializer(alb_basic_listener_endpoint):
4041
# GIVEN
4142
url = f"{alb_basic_listener_endpoint}/todos"
@@ -74,6 +75,7 @@ def test_alb_headers_serializer(alb_basic_listener_endpoint):
7475
assert response.cookies.get(last_cookie.name) == last_cookie.value
7576

7677

78+
@pytest.mark.xdist_group(name="event_handler")
7779
def test_alb_multi_value_headers_serializer(alb_multi_value_header_listener_endpoint):
7880
# GIVEN
7981
url = f"{alb_multi_value_header_listener_endpoint}/todos"
@@ -112,6 +114,7 @@ def test_alb_multi_value_headers_serializer(alb_multi_value_header_listener_endp
112114
assert response.cookies.get(cookie.name) == cookie.value
113115

114116

117+
@pytest.mark.xdist_group(name="event_handler")
115118
def test_api_gateway_rest_headers_serializer(apigw_rest_endpoint):
116119
# GIVEN
117120
url = f"{apigw_rest_endpoint}todos"
@@ -147,6 +150,7 @@ def test_api_gateway_rest_headers_serializer(apigw_rest_endpoint):
147150
assert response.cookies.get(cookie.name) == cookie.value
148151

149152

153+
@pytest.mark.xdist_group(name="event_handler")
150154
def test_api_gateway_http_headers_serializer(apigw_http_endpoint):
151155
# GIVEN
152156
url = f"{apigw_http_endpoint}todos"
@@ -182,6 +186,7 @@ def test_api_gateway_http_headers_serializer(apigw_http_endpoint):
182186
assert response.cookies.get(cookie.name) == cookie.value
183187

184188

189+
@pytest.mark.xdist_group(name="event_handler")
185190
def test_lambda_function_url_headers_serializer(lambda_function_url_endpoint):
186191
# GIVEN
187192
url = f"{lambda_function_url_endpoint}todos" # the function url endpoint already has the trailing /

tests/e2e/event_handler/test_paths_ending_with_slash.py

+4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def lambda_function_url_endpoint(infrastructure: dict) -> str:
3333
return infrastructure.get("LambdaFunctionUrl", "")
3434

3535

36+
@pytest.mark.xdist_group(name="event_handler")
3637
def test_api_gateway_rest_trailing_slash(apigw_rest_endpoint):
3738
# GIVEN API URL ends in a trailing slash
3839
url = f"{apigw_rest_endpoint}todos/"
@@ -51,6 +52,7 @@ def test_api_gateway_rest_trailing_slash(apigw_rest_endpoint):
5152
assert response.status_code == 200
5253

5354

55+
@pytest.mark.xdist_group(name="event_handler")
5456
def test_api_gateway_http_trailing_slash(apigw_http_endpoint):
5557
# GIVEN the URL for the API ends in a trailing slash API gateway should return a 404
5658
url = f"{apigw_http_endpoint}todos/"
@@ -67,6 +69,7 @@ def test_api_gateway_http_trailing_slash(apigw_http_endpoint):
6769
)
6870

6971

72+
@pytest.mark.xdist_group(name="event_handler")
7073
def test_lambda_function_url_trailing_slash(lambda_function_url_endpoint):
7174
# GIVEN the URL for the API ends in a trailing slash it should behave as if there was not one
7275
url = f"{lambda_function_url_endpoint}todos/" # the function url endpoint already has the trailing /
@@ -83,6 +86,7 @@ def test_lambda_function_url_trailing_slash(lambda_function_url_endpoint):
8386
)
8487

8588

89+
@pytest.mark.xdist_group(name="event_handler")
8690
def test_alb_url_trailing_slash(alb_multi_value_header_listener_endpoint):
8791
# GIVEN url has a trailing slash - it should behave as if there was not one
8892
url = f"{alb_multi_value_header_listener_endpoint}/todos/"

tests/e2e/idempotency/conftest.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import pytest
22

33
from tests.e2e.idempotency.infrastructure import IdempotencyDynamoDBStack
4-
from tests.e2e.utils.infrastructure import call_once
54

65

7-
@pytest.fixture(autouse=True, scope="module")
8-
def infrastructure(tmp_path_factory: pytest.TempPathFactory, worker_id: str):
6+
@pytest.fixture(autouse=True, scope="package")
7+
def infrastructure():
98
"""Setup and teardown logic for E2E test infrastructure
109
1110
Yields
@@ -15,10 +14,6 @@ def infrastructure(tmp_path_factory: pytest.TempPathFactory, worker_id: str):
1514
"""
1615
stack = IdempotencyDynamoDBStack()
1716
try:
18-
return (
19-
yield from call_once(
20-
job_id=stack.feature_name, task=stack.deploy, tmp_path_factory=tmp_path_factory, worker_id=worker_id
21-
)
22-
)
17+
yield stack.deploy()
2318
finally:
2419
stack.delete()

tests/e2e/idempotency/test_idempotency_dynamodb.py

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def idempotency_table_name(infrastructure: dict) -> str:
2727
return infrastructure.get("DynamoDBTable", "")
2828

2929

30+
@pytest.mark.xdist_group(name="idempotency")
3031
def test_ttl_caching_expiration_idempotency(ttl_cache_expiration_handler_fn_arn: str):
3132
# GIVEN
3233
payload = json.dumps({"message": "Lambda Powertools - TTL 5s"})
@@ -56,6 +57,7 @@ def test_ttl_caching_expiration_idempotency(ttl_cache_expiration_handler_fn_arn:
5657
assert third_execution_response != second_execution_response
5758

5859

60+
@pytest.mark.xdist_group(name="idempotency")
5961
def test_ttl_caching_timeout_idempotency(ttl_cache_timeout_handler_fn_arn: str):
6062
# GIVEN
6163
payload_timeout_execution = json.dumps({"sleep": 5, "message": "Lambda Powertools - TTL 1s"})
@@ -79,6 +81,7 @@ def test_ttl_caching_timeout_idempotency(ttl_cache_timeout_handler_fn_arn: str):
7981
assert payload_working_execution == execution_working_response
8082

8183

84+
@pytest.mark.xdist_group(name="idempotency")
8285
def test_parallel_execution_idempotency(parallel_execution_handler_fn_arn: str):
8386
# GIVEN
8487
arguments = json.dumps({"message": "Lambda Powertools - Parallel execution"})

tests/e2e/logger/conftest.py

+3-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import pytest
22

33
from tests.e2e.logger.infrastructure import LoggerStack
4-
from tests.e2e.utils.infrastructure import call_once
54

65

7-
@pytest.fixture(autouse=True, scope="module")
8-
def infrastructure(tmp_path_factory, worker_id):
6+
@pytest.fixture(autouse=True, scope="package")
7+
def infrastructure():
98
"""Setup and teardown logic for E2E test infrastructure
109
1110
Yields
@@ -15,13 +14,6 @@ def infrastructure(tmp_path_factory, worker_id):
1514
"""
1615
stack = LoggerStack()
1716
try:
18-
return (
19-
yield from call_once(
20-
job_id=stack.feature_name,
21-
task=stack.deploy,
22-
tmp_path_factory=tmp_path_factory,
23-
worker_id=worker_id,
24-
)
25-
)
17+
yield stack.deploy()
2618
finally:
2719
stack.delete()

tests/e2e/logger/test_logger.py

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def basic_handler_fn_arn(infrastructure: dict) -> str:
1717
return infrastructure.get("BasicHandlerArn", "")
1818

1919

20+
@pytest.mark.xdist_group(name="logger")
2021
def test_basic_lambda_logs_visible(basic_handler_fn, basic_handler_fn_arn):
2122
# GIVEN
2223
message = "logs should be visible with default settings"

tests/e2e/metrics/conftest.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import pytest
22

33
from tests.e2e.metrics.infrastructure import MetricsStack
4-
from tests.e2e.utils.infrastructure import call_once
54

65

7-
@pytest.fixture(autouse=True, scope="module")
8-
def infrastructure(tmp_path_factory, worker_id):
6+
@pytest.fixture(autouse=True, scope="package")
7+
def infrastructure():
98
"""Setup and teardown logic for E2E test infrastructure
109
1110
Yields
@@ -15,10 +14,6 @@ def infrastructure(tmp_path_factory, worker_id):
1514
"""
1615
stack = MetricsStack()
1716
try:
18-
return (
19-
yield from call_once(
20-
job_id=stack.feature_name, task=stack.deploy, tmp_path_factory=tmp_path_factory, worker_id=worker_id
21-
)
22-
)
17+
yield stack.deploy()
2318
finally:
2419
stack.delete()

tests/e2e/metrics/test_metrics.py

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def cold_start_fn_arn(infrastructure: dict) -> str:
2828
METRIC_NAMESPACE = "powertools-e2e-metric"
2929

3030

31+
@pytest.mark.xdist_group(name="metrics")
3132
def test_basic_lambda_metric_is_visible(basic_handler_fn: str, basic_handler_fn_arn: str):
3233
# GIVEN
3334
metric_name = data_builder.build_metric_name()
@@ -47,6 +48,7 @@ def test_basic_lambda_metric_is_visible(basic_handler_fn: str, basic_handler_fn_
4748
assert metric_values == [3.0]
4849

4950

51+
@pytest.mark.xdist_group(name="metrics")
5052
def test_cold_start_metric(cold_start_fn_arn: str, cold_start_fn: str):
5153
# GIVEN
5254
metric_name = "ColdStart"

tests/e2e/parameters/conftest.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import pytest
22

33
from tests.e2e.parameters.infrastructure import ParametersStack
4-
from tests.e2e.utils.infrastructure import call_once
54

65

7-
@pytest.fixture(autouse=True, scope="module")
8-
def infrastructure(tmp_path_factory, worker_id):
6+
@pytest.fixture(autouse=True, scope="package")
7+
def infrastructure():
98
"""Setup and teardown logic for E2E test infrastructure
109
1110
Yields
@@ -15,10 +14,6 @@ def infrastructure(tmp_path_factory, worker_id):
1514
"""
1615
stack = ParametersStack()
1716
try:
18-
return (
19-
yield from call_once(
20-
job_id=stack.feature_name, task=stack.deploy, tmp_path_factory=tmp_path_factory, worker_id=worker_id
21-
)
22-
)
17+
yield stack.deploy()
2318
finally:
2419
stack.delete()

tests/e2e/parameters/test_appconfig.py

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def parameter_appconfig_freeform_profile(infrastructure: dict) -> str:
3535
return infrastructure.get("AppConfigProfile", "")
3636

3737

38+
@pytest.mark.xdist_group(name="parameters")
3839
def test_get_parameter_appconfig_freeform(
3940
parameter_appconfig_freeform_handler_fn_arn: str,
4041
parameter_appconfig_freeform_value: str,

tests/e2e/parameters/test_ssm.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def parameters_list(infrastructure: dict) -> List[str]:
1717
return json.loads(param_list)
1818

1919

20-
#
20+
@pytest.mark.xdist_group(name="parameters")
2121
def test_get_parameters_by_name(
2222
ssm_get_parameters_by_name_fn_arn: str,
2323
parameters_list: str,

tests/e2e/streaming/conftest.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import pytest
22

33
from tests.e2e.streaming.infrastructure import StreamingStack
4-
from tests.e2e.utils.infrastructure import call_once
54

65

7-
@pytest.fixture(autouse=True, scope="module")
8-
def infrastructure(tmp_path_factory, worker_id):
6+
@pytest.fixture(autouse=True, scope="package")
7+
def infrastructure():
98
"""Setup and teardown logic for E2E test infrastructure
109
1110
Yields
@@ -15,10 +14,6 @@ def infrastructure(tmp_path_factory, worker_id):
1514
"""
1615
stack = StreamingStack()
1716
try:
18-
return (
19-
yield from call_once(
20-
job_id=stack.feature_name, task=stack.deploy, tmp_path_factory=tmp_path_factory, worker_id=worker_id
21-
)
22-
)
17+
yield stack.deploy()
2318
finally:
2419
stack.delete()

0 commit comments

Comments
 (0)