16
16
17
17
from collections import namedtuple
18
18
from platform import python_implementation
19
- from unittest import mock
19
+ from unittest import mock , skipIf
20
20
21
21
from opentelemetry .sdk .metrics import MeterProvider
22
22
from opentelemetry .sdk .metrics .export import InMemoryMetricReader
@@ -97,7 +97,6 @@ def test_system_metrics_instrument(self):
97
97
for scope_metrics in resource_metrics .scope_metrics :
98
98
for metric in scope_metrics .metrics :
99
99
metric_names .append (metric .name )
100
- self .assertEqual (len (metric_names ), 21 )
101
100
102
101
observer_names = [
103
102
"system.cpu.time" ,
@@ -117,11 +116,16 @@ def test_system_metrics_instrument(self):
117
116
"system.thread_count" ,
118
117
f"process.runtime.{ self .implementation } .memory" ,
119
118
f"process.runtime.{ self .implementation } .cpu_time" ,
120
- f"process.runtime.{ self .implementation } .gc_count" ,
121
119
f"process.runtime.{ self .implementation } .thread_count" ,
122
120
f"process.runtime.{ self .implementation } .context_switches" ,
123
121
f"process.runtime.{ self .implementation } .cpu.utilization" ,
124
122
]
123
+
124
+ if self .implementation == "pypy" :
125
+ self .assertEqual (len (metric_names ), 20 )
126
+ else :
127
+ self .assertEqual (len (metric_names ), 21 )
128
+ observer_names .append (f"process.runtime.{ self .implementation } .gc_count" ,)
125
129
126
130
for observer in metric_names :
127
131
self .assertIn (observer , observer_names )
@@ -131,11 +135,13 @@ def test_runtime_metrics_instrument(self):
131
135
runtime_config = {
132
136
"process.runtime.memory" : ["rss" , "vms" ],
133
137
"process.runtime.cpu.time" : ["user" , "system" ],
134
- "process.runtime.gc_count" : None ,
135
138
"process.runtime.thread_count" : None ,
136
139
"process.runtime.cpu.utilization" : None ,
137
140
"process.runtime.context_switches" : ["involuntary" , "voluntary" ],
138
141
}
142
+
143
+ if self .implementation != "pypy" :
144
+ runtime_config ["process.runtime.gc_count" ] = None
139
145
140
146
reader = InMemoryMetricReader ()
141
147
meter_provider = MeterProvider (metric_readers = [reader ])
@@ -147,17 +153,21 @@ def test_runtime_metrics_instrument(self):
147
153
for scope_metrics in resource_metrics .scope_metrics :
148
154
for metric in scope_metrics .metrics :
149
155
metric_names .append (metric .name )
150
- self .assertEqual (len (metric_names ), 6 )
151
156
152
157
observer_names = [
153
158
f"process.runtime.{ self .implementation } .memory" ,
154
159
f"process.runtime.{ self .implementation } .cpu_time" ,
155
- f"process.runtime.{ self .implementation } .gc_count" ,
156
160
f"process.runtime.{ self .implementation } .thread_count" ,
157
161
f"process.runtime.{ self .implementation } .context_switches" ,
158
162
f"process.runtime.{ self .implementation } .cpu.utilization" ,
159
163
]
160
164
165
+ if self .implementation == "pypy" :
166
+ self .assertEqual (len (metric_names ), 5 )
167
+ else :
168
+ self .assertEqual (len (metric_names ), 6 )
169
+ observer_names .append (f"process.runtime.{ self .implementation } .gc_count" )
170
+
161
171
for observer in metric_names :
162
172
self .assertIn (observer , observer_names )
163
173
observer_names .remove (observer )
@@ -781,6 +791,7 @@ def test_runtime_cpu_time(self, mock_process_cpu_times):
781
791
)
782
792
783
793
@mock .patch ("gc.get_count" )
794
+ @skipIf (python_implementation ().lower () == "pypy" , "not supported for pypy" )
784
795
def test_runtime_get_count (self , mock_gc_get_count ):
785
796
mock_gc_get_count .configure_mock (** {"return_value" : (1 , 2 , 3 )})
786
797
0 commit comments