Skip to content

Commit 28a41df

Browse files
committed
chore(test): print instance id in pytest header
Instance ID is useful to find the instance in the AWS account, but we only ever log instance IP and hostname. Let's add it to the pytest header so it's easy to find. Signed-off-by: Riccardo Mancini <[email protected]>
1 parent d5f3513 commit 28a41df

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

tests/conftest.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ def pytest_addoption(parser):
7777

7878
def pytest_report_header():
7979
"""Pytest hook to print relevant metadata in the logs"""
80-
return f"EC2 AMI: {global_props.ami}"
80+
return "\n".join([
81+
f"EC2 AMI: {global_props.ami}",
82+
f"EC2 Instance ID: {global_props.instance_id}",
83+
])
8184

8285

8386
@pytest.hookimpl(wrapper=True, tryfirst=True)

tests/framework/properties.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,11 @@ def __init__(self):
9292
self.environment = self._detect_environment()
9393
if self.is_ec2:
9494
self.instance = imdsv2_get("/meta-data/instance-type")
95+
self.instance_id = imdsv2_get("/meta-data/instance-id")
9596
self.ami = imdsv2_get("/meta-data/ami-id")
9697
else:
9798
self.instance = "NA"
99+
self.instance_id = "NA"
98100
self.ami = "NA"
99101

100102
@property

0 commit comments

Comments
 (0)