Author: Antonio Cuni <anto.c...@gmail.com> Branch: fix-vmprof-stacklet-switch-2 Changeset: r93192:d5d42f493530 Date: 2017-11-28 15:47 +0100 http://bitbucket.org/pypy/pypy/changeset/d5d42f493530/
Log: WIP: introduce a pytest fixture which allow us to easily use a global FakeVMProf instead of the real one diff --git a/rpython/rlib/rvmprof/test/support.py b/rpython/rlib/rvmprof/test/support.py --- a/rpython/rlib/rvmprof/test/support.py +++ b/rpython/rlib/rvmprof/test/support.py @@ -1,3 +1,5 @@ +import pytest +from rpython.rlib import rvmprof class FakeVMProf(object): @@ -24,3 +26,12 @@ def is_sampling_enabled(self): return self._ignore_signals == 0 + +@pytest.fixture +def fakevmprof(request, monkeypatch): + fake = FakeVMProf() + def _get_fake_vmprof(): + return fake + monkeypatch.setattr(rvmprof.rvmprof, '_get_vmprof', _get_fake_vmprof) + return fake + diff --git a/rpython/rlib/rvmprof/test/test_support.py b/rpython/rlib/rvmprof/test/test_support.py --- a/rpython/rlib/rvmprof/test/test_support.py +++ b/rpython/rlib/rvmprof/test/test_support.py @@ -1,5 +1,6 @@ import pytest -from rpython.rlib.rvmprof.test.support import FakeVMProf +from rpython.rlib import rvmprof +from rpython.rlib.rvmprof.test.support import FakeVMProf, fakevmprof class TestFakeVMProf(object): @@ -21,3 +22,17 @@ # pytest.raises(AssertionError, "fake.start_sampling()") + + +class TestFixture(object): + + def test_fixture(self, fakevmprof): + assert isinstance(fakevmprof, FakeVMProf) + assert rvmprof.rvmprof._get_vmprof() is fakevmprof + # + # tweak sampling using the "real" API, and check that we actually used + # the fake + rvmprof.start_sampling() + assert fakevmprof.is_sampling_enabled + rvmprof.stop_sampling() + assert not fakevmprof.is_sampling_enabled _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit