Debian Codegraph @

pypy/tool/pytest/test/test_pytestsupport.py

raw symbols SCIP
1 from pypy.interpreter.error import OperationError
2 from pypy.tool.pytest.appsupport import AppExceptionInfo
3 import py
4 import pypy
5 conftestpath = py.path.local(pypy.__file__).dirpath("conftest.py")
6
7 pytest_plugins = "pytester"
8
9 def test_appexecinfo(space):
10 try:
11 space.appexec([], "(): raise ValueError")
12 except OperationError as e:
13 appex = AppExceptionInfo(space, e)
14 else:
15 py.test.fail("did not raise!")
16 assert appex.exconly().find('ValueError') != -1
17 assert appex.exconly(tryshort=True).find('ValueError') != -1
18 assert appex.errisinstance(ValueError)
19 assert not appex.errisinstance(RuntimeError)
20 class A:
21 pass
22 assert not appex.errisinstance(A)
23
24 # this is used by test_wrapped_function_with_different_name below
25 def inc(self, x):
26 return x+1
27
28 class AppTestWithWrappedInterplevelAttributes:
29 def setup_class(cls):
30 space = cls.space
31 cls.w_some1 = space.wrap(42)
32
33 def setup_method(self, meth):
34 self.w_some2 = self.space.wrap(23)
35
36 def test_values_arrive(self):
37 assert self.some1 == 42
38 assert self.some2 == 23
39
40 def test_values_arrive2(self):
41 assert self.some1 == 42
42
43 def w_compute(self, x):
44 return x + 2
45
46 def test_equal(self):
47 assert self.compute(3) == 5
48
49 w_inc = inc
50
51 def test_wrapped_function_with_different_name(self):
52 assert self.inc(41) == 42
53
54
55 def test_app_test_blow(testdir):
56 conftestpath.copy(testdir.tmpdir)
57 sorter = testdir.inline_runsource("""class AppTestBlow:
58 def test_one(self): exec('blow')
59 """)
60
61 reports = sorter.getreports("pytest_runtest_logreport")
62 setup, ev, teardown = reports
63 assert ev.failed
64 assert setup.passed
65 assert teardown.passed
66 assert 'NameError' in ev.longrepr.reprcrash.message
67 assert 'blow' in ev.longrepr.reprcrash.message