def test_tracing_sampler_does_not_sample_too_often(): pytest.importorskip('yappi') # pytest-cov cannot detect a callback function registered by # :func:`sys.setprofile`. class fake_profiler(object): samples = [] @classmethod def sample(cls, frame): cls.samples.append(frame) @classmethod def count_and_clear_samples(cls): count = len(cls.samples) del cls.samples[:] return count sampler = TracingSampler(0.1) sampler._profile(fake_profiler, None, None, None) assert fake_profiler.count_and_clear_samples() == 1 sampler._profile(fake_profiler, None, None, None) assert fake_profiler.count_and_clear_samples() == 0 spin(0.5) sampler._profile(fake_profiler, None, None, None) assert fake_profiler.count_and_clear_samples() == 1
def test_tracing_sampler_does_not_sample_too_often(): # pytest-cov cannot detect a callback function registered by # :func:`sys.setprofile`. class fake_profiler(object): samples = [] @classmethod def sample(cls, frame): cls.samples.append(frame) @classmethod def count_and_clear_samples(cls): count = len(cls.samples) del cls.samples[:] return count sampler = TracingSampler(0.1) sampler._profile(fake_profiler, None, None, None) assert fake_profiler.count_and_clear_samples() == 1 sampler._profile(fake_profiler, None, None, None) assert fake_profiler.count_and_clear_samples() == 0 spin(0.5) sampler._profile(fake_profiler, None, None, None) assert fake_profiler.count_and_clear_samples() == 1
def test_tracing_sampler(): _test_sampling_profiler(TracingSampler(0.0001))
def test_tracing_sampler(): pytest.importorskip('yappi') _test_sampling_profiler(TracingSampler(0.0001))