1616
1717from collections import namedtuple
1818from platform import python_implementation
19- from unittest import mock
19+ from unittest import mock , skipIf
2020
2121from opentelemetry .sdk .metrics import MeterProvider
2222from opentelemetry .sdk .metrics .export import InMemoryMetricReader
@@ -97,7 +97,6 @@ def test_system_metrics_instrument(self):
9797 for scope_metrics in resource_metrics .scope_metrics :
9898 for metric in scope_metrics .metrics :
9999 metric_names .append (metric .name )
100- self .assertEqual (len (metric_names ), 21 )
101100
102101 observer_names = [
103102 "system.cpu.time" ,
@@ -117,11 +116,16 @@ def test_system_metrics_instrument(self):
117116 "system.thread_count" ,
118117 f"process.runtime.{ self .implementation } .memory" ,
119118 f"process.runtime.{ self .implementation } .cpu_time" ,
120- f"process.runtime.{ self .implementation } .gc_count" ,
121119 f"process.runtime.{ self .implementation } .thread_count" ,
122120 f"process.runtime.{ self .implementation } .context_switches" ,
123121 f"process.runtime.{ self .implementation } .cpu.utilization" ,
124122 ]
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" ,)
125129
126130 for observer in metric_names :
127131 self .assertIn (observer , observer_names )
@@ -131,11 +135,13 @@ def test_runtime_metrics_instrument(self):
131135 runtime_config = {
132136 "process.runtime.memory" : ["rss" , "vms" ],
133137 "process.runtime.cpu.time" : ["user" , "system" ],
134- "process.runtime.gc_count" : None ,
135138 "process.runtime.thread_count" : None ,
136139 "process.runtime.cpu.utilization" : None ,
137140 "process.runtime.context_switches" : ["involuntary" , "voluntary" ],
138141 }
142+
143+ if self .implementation != "pypy" :
144+ runtime_config ["process.runtime.gc_count" ] = None
139145
140146 reader = InMemoryMetricReader ()
141147 meter_provider = MeterProvider (metric_readers = [reader ])
@@ -147,17 +153,21 @@ def test_runtime_metrics_instrument(self):
147153 for scope_metrics in resource_metrics .scope_metrics :
148154 for metric in scope_metrics .metrics :
149155 metric_names .append (metric .name )
150- self .assertEqual (len (metric_names ), 6 )
151156
152157 observer_names = [
153158 f"process.runtime.{ self .implementation } .memory" ,
154159 f"process.runtime.{ self .implementation } .cpu_time" ,
155- f"process.runtime.{ self .implementation } .gc_count" ,
156160 f"process.runtime.{ self .implementation } .thread_count" ,
157161 f"process.runtime.{ self .implementation } .context_switches" ,
158162 f"process.runtime.{ self .implementation } .cpu.utilization" ,
159163 ]
160164
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+
161171 for observer in metric_names :
162172 self .assertIn (observer , observer_names )
163173 observer_names .remove (observer )
@@ -781,6 +791,7 @@ def test_runtime_cpu_time(self, mock_process_cpu_times):
781791 )
782792
783793 @mock .patch ("gc.get_count" )
794+ @skipIf (python_implementation ().lower () == "pypy" , "not supported for pypy" )
784795 def test_runtime_get_count (self , mock_gc_get_count ):
785796 mock_gc_get_count .configure_mock (** {"return_value" : (1 , 2 , 3 )})
786797
0 commit comments