Debian Codegraph @

lib_pypy/hpy/debug/pytest.py

raw symbols SCIP
1 # hpy.debug / pytest integration
2
3 import pytest
4 from .leakdetector import LeakDetector
5
6 # For now "hpy_debug" just does leak detection, but in the future it might
7 # grows extra features: that's why it's called generically "hpy_debug" instead
8 # of "detect_leaks".
9
10 # NOTE: the fixture itself is currently untested :(. It turns out that testing
11 # that the fixture raises during the teardown is complicated and probably
12 # requires to write a full-fledged plugin. We might want to turn this into a
13 # real plugin in the future, but for now I think this is enough.
14
15 # pypy still uses a very ancient version of pytest, 2.9.2: pytest<3.x needs to
16 # use @yield_fixture, which is deprecated in newer version of pytest (where
17 # you can just use @fixture)
18 if pytest.__version__ < '3':
19 fixture = pytest.yield_fixture
20 else:
21 fixture = pytest.fixture
22
23 @fixture
24 def hpy_debug(request):
25 """
26 pytest fixture which makes it possible to control hpy.debug from within a test.
27
28 In particular, it automatically check that the test doesn't leak.
29 """
30 with LeakDetector() as ld:
31 yield ld