I have a class A that initializes a Counter in its init
from prometheus_client import Counter
class A:def __init__(self):self.my_counter = Counter('an_awesome_counter')def method_1(self):return 1def method_2(self):return 2
Then I write test class :
import unittest
import Aclass ATests(unittest.TestCase):def setUp(self):self.a = A()def tearDown(self):self.a = Nonedef method_1_test(self):....def method_2_test(self):....
Thing is, if I run the test separately, they are fine. Yet when I run them together (Run the whole ATests class), I have the error as:
ValueError: Duplicated timeseries in CollectorRegistry:{'an_awesome_counter'}
So it seems that the python environment isn't reset after each test run. I check the CollectorRegistry and there is a method to unregister collector, but it seems a bit ugly to do that.
I wonder if there is another way to solve this problem? Like forcing the test to run with new environment every time for example..
Thank you.