Skip to content

Commit 1ae8f53

Browse files
committed
added clean up in tests and minor changes
1 parent 896eccc commit 1ae8f53

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

aws_xray_sdk/core/models/dummy_entities.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ class DummySegment(Segment):
1616
"""
1717

1818
def __init__(self, name='dummy'):
19-
noOpID = os.getenv('AWS_XRAY_NOOP_ID')
20-
if not noOpID or noOpID.lower() == 'true':
19+
no_op_id = os.getenv('AWS_XRAY_NOOP_ID')
20+
if not no_op_id or no_op_id.lower() == 'true':
2121
super(DummySegment, self).__init__(name=name, traceid=NoOpTraceId().to_id(), entityid='0000000000000000')
2222
else:
2323
super(DummySegment, self).__init__(name=name, traceid=TraceId().to_id())
@@ -88,8 +88,8 @@ class DummySubsegment(Subsegment):
8888

8989
def __init__(self, segment, name='dummy'):
9090
super(DummySubsegment, self).__init__(name, 'dummy', segment)
91-
noOpID = os.getenv('AWS_XRAY_NOOP_ID')
92-
if not noOpID or noOpID.lower() == 'true':
91+
no_op_id = os.getenv('AWS_XRAY_NOOP_ID')
92+
if not no_op_id or no_op_id.lower() == 'true':
9393
super(Subsegment, self).__init__(name, entity_id='0000000000000000')
9494
self.sampled = False
9595

tests/test_traceid.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
import os
2+
import pytest
23
from aws_xray_sdk.core import xray_recorder
3-
44
from aws_xray_sdk.core.models.traceid import TraceId
55

66

7+
@pytest.fixture(autouse=True)
8+
def cleanup():
9+
"""
10+
Clean up Environmental Variable for enable before and after tests
11+
"""
12+
if 'AWS_XRAY_NOOP_ID' in os.environ:
13+
del os.environ['AWS_XRAY_NOOP_ID']
14+
yield
15+
if 'AWS_XRAY_NOOP_ID' in os.environ:
16+
del os.environ['AWS_XRAY_NOOP_ID']
17+
18+
719
def test_id_format():
820
trace_id = TraceId().to_id()
921
assert len(trace_id) == 35
@@ -58,7 +70,6 @@ def test_id_generation_noop_true():
5870

5971
# Close the segment
6072
xray_recorder.end_segment()
61-
os.unsetenv('AWS_XRAY_NOOP_ID')
6273

6374
assert segment.id == '0000000000000000'
6475
assert segment.trace_id == '1-00000000-000000000000000000000000'
@@ -77,7 +88,6 @@ def test_id_generation_noop_false():
7788

7889
# Close the segment
7990
xray_recorder.end_segment()
80-
os.unsetenv('AWS_XRAY_NOOP_ID')
8191

8292
assert segment.id != '0000000000000000'
8393
assert segment.trace_id != '1-00000000-000000000000000000000000'

0 commit comments

Comments
 (0)