@@ -348,17 +348,6 @@ def collect(self):
348
348
return [self .metric_family ]
349
349
350
350
351
- def _expect_metric_exception (registry , expected_error ):
352
- try :
353
- generate_latest (registry )
354
- except expected_error as exception :
355
- assert isinstance (exception .args [- 1 ], core .Metric )
356
- # Got a valid error as expected, return quietly
357
- return
358
-
359
- raise RuntimeError ('Expected exception not raised' )
360
-
361
-
362
351
@pytest .mark .parametrize ('MetricFamily' , [
363
352
core .CounterMetricFamily ,
364
353
core .GaugeMetricFamily ,
@@ -373,7 +362,12 @@ def _expect_metric_exception(registry, expected_error):
373
362
def test_basic_metric_families (registry , MetricFamily , value , error ):
374
363
metric_family = MetricFamily (MetricFamily .__name__ , 'help' )
375
364
registry .register (Collector (metric_family , value ))
376
- _expect_metric_exception (registry , error )
365
+ try :
366
+ generate_latest (registry )
367
+ except error as exception :
368
+ # Got a valid error as expected, return quietly
369
+ return
370
+ raise RuntimeError ('Expected exception not raised' )
377
371
378
372
379
373
@pytest .mark .parametrize ('count_value,sum_value,error' , [
@@ -389,14 +383,18 @@ def test_basic_metric_families(registry, MetricFamily, value, error):
389
383
def test_summary_metric_family (registry , count_value , sum_value , error ):
390
384
metric_family = core .SummaryMetricFamily ('summary' , 'help' )
391
385
registry .register (Collector (metric_family , count_value , sum_value ))
392
- _expect_metric_exception (registry , error )
386
+ try :
387
+ generate_latest (registry )
388
+ except error as exception :
389
+ # Got a valid error as expected, return quietly
390
+ return
391
+ raise RuntimeError ('Expected exception not raised' )
393
392
394
393
395
394
@pytest .mark .parametrize ('MetricFamily' , [
396
395
core .GaugeHistogramMetricFamily ,
397
396
])
398
397
@pytest .mark .parametrize ('buckets,sum_value,error' , [
399
- ([('spam' , 0 ), ('eggs' , 0 )], None , TypeError ),
400
398
([('spam' , 0 ), ('eggs' , None )], 0 , TypeError ),
401
399
([('spam' , 0 ), (None , 0 )], 0 , AttributeError ),
402
400
([('spam' , None ), ('eggs' , 0 )], 0 , TypeError ),
@@ -408,7 +406,12 @@ def test_summary_metric_family(registry, count_value, sum_value, error):
408
406
def test_histogram_metric_families (MetricFamily , registry , buckets , sum_value , error ):
409
407
metric_family = MetricFamily (MetricFamily .__name__ , 'help' )
410
408
registry .register (Collector (metric_family , buckets , sum_value ))
411
- _expect_metric_exception (registry , error )
409
+ try :
410
+ generate_latest (registry )
411
+ except error as exception :
412
+ # Got a valid error as expected, return quietly
413
+ return
414
+ raise RuntimeError ('Expected exception not raised' )
412
415
413
416
414
417
if __name__ == '__main__' :
0 commit comments