call site 1 for code.Code.new
doc/example/pytest/test_failures.py - line 9
6
7
8
9
10
11
12
13
   def test_failure_demo_fails_properly(): 
       config = py.test.config._reparse([failure_demo]) 
       session = config.initsession()
->     session.main()
       l = session.getitemoutcomepairs(Failed)
       assert len(l) == 21 
       l = session.getitemoutcomepairs(Passed)
       assert not l 
test/session.py - line 63
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
   def main(self): 
       """ main loop for running tests. """
       colitems = self.config.getcolitems()
       try:
           self.header(colitems) 
           try:
               try:
                   for colitem in colitems: 
->                     self.runtraced(colitem)
               except KeyboardInterrupt: 
                   raise 
           finally: 
               self.footer(colitems) 
       except Exit, ex:
           pass
       return self.getitemoutcomepairs(Failed)
test/session.py - line 84
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
   def runtraced(self, colitem):
       if self.shouldclose(): 
           raise Exit, "received external close signal" 
   
       outcome = None 
       colitem.startcapture() 
       try: 
           self.start(colitem)
           try: 
               try:
                   if colitem._stickyfailure: 
                       raise colitem._stickyfailure 
->                 outcome = self.run(colitem) 
               except (KeyboardInterrupt, Exit): 
                   raise 
               except Outcome, outcome: 
                   if outcome.excinfo is None: 
                       outcome.excinfo = py.code.ExceptionInfo() 
               except: 
                   excinfo = py.code.ExceptionInfo() 
                   outcome = Failed(excinfo=excinfo) 
               assert (outcome is None or 
                       isinstance(outcome, (list, Outcome)))
           finally: 
               self.finish(colitem, outcome) 
           if isinstance(outcome, Failed) and self.config.option.exitfirst:
               py.test.exit("exit on first problem configured.", item=colitem)
       finally: 
           colitem.finishcapture()
test/session.py - line 119
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
   def run(self, colitem): 
       if self.config.option.collectonly and isinstance(colitem, py.test.collect.Item): 
           return 
       if isinstance(colitem, py.test.collect.Item): 
           colitem._skipbykeyword(self.config.option.keyword)
       res = colitem.run() 
       if res is None: 
           return Passed() 
       elif not isinstance(res, (list, tuple)): 
           raise TypeError("%r.run() returned neither "
                           "list, tuple nor None: %r" % (colitem, res))
       else: 
           finish = self.startiteration(colitem, res)
           try: 
               for name in res: 
                   obj = colitem.join(name) 
                   assert obj is not None 
->                 self.runtraced(obj) 
           finally: 
               if finish: 
                   finish() 
       return res 
test/session.py - line 84
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
   def runtraced(self, colitem):
       if self.shouldclose(): 
           raise Exit, "received external close signal" 
   
       outcome = None 
       colitem.startcapture() 
       try: 
           self.start(colitem)
           try: 
               try:
                   if colitem._stickyfailure: 
                       raise colitem._stickyfailure 
->                 outcome = self.run(colitem) 
               except (KeyboardInterrupt, Exit): 
                   raise 
               except Outcome, outcome: 
                   if outcome.excinfo is None: 
                       outcome.excinfo = py.code.ExceptionInfo() 
               except: 
                   excinfo = py.code.ExceptionInfo() 
                   outcome = Failed(excinfo=excinfo) 
               assert (outcome is None or 
                       isinstance(outcome, (list, Outcome)))
           finally: 
               self.finish(colitem, outcome) 
           if isinstance(outcome, Failed) and self.config.option.exitfirst:
               py.test.exit("exit on first problem configured.", item=colitem)
       finally: 
           colitem.finishcapture()
test/session.py - line 119
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
   def run(self, colitem): 
       if self.config.option.collectonly and isinstance(colitem, py.test.collect.Item): 
           return 
       if isinstance(colitem, py.test.collect.Item): 
           colitem._skipbykeyword(self.config.option.keyword)
       res = colitem.run() 
       if res is None: 
           return Passed() 
       elif not isinstance(res, (list, tuple)): 
           raise TypeError("%r.run() returned neither "
                           "list, tuple nor None: %r" % (colitem, res))
       else: 
           finish = self.startiteration(colitem, res)
           try: 
               for name in res: 
                   obj = colitem.join(name) 
                   assert obj is not None 
->                 self.runtraced(obj) 
           finally: 
               if finish: 
                   finish() 
       return res 
test/session.py - line 84
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
   def runtraced(self, colitem):
       if self.shouldclose(): 
           raise Exit, "received external close signal" 
   
       outcome = None 
       colitem.startcapture() 
       try: 
           self.start(colitem)
           try: 
               try:
                   if colitem._stickyfailure: 
                       raise colitem._stickyfailure 
->                 outcome = self.run(colitem) 
               except (KeyboardInterrupt, Exit): 
                   raise 
               except Outcome, outcome: 
                   if outcome.excinfo is None: 
                       outcome.excinfo = py.code.ExceptionInfo() 
               except: 
                   excinfo = py.code.ExceptionInfo() 
                   outcome = Failed(excinfo=excinfo) 
               assert (outcome is None or 
                       isinstance(outcome, (list, Outcome)))
           finally: 
               self.finish(colitem, outcome) 
           if isinstance(outcome, Failed) and self.config.option.exitfirst:
               py.test.exit("exit on first problem configured.", item=colitem)
       finally: 
           colitem.finishcapture()
test/session.py - line 119
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
   def run(self, colitem): 
       if self.config.option.collectonly and isinstance(colitem, py.test.collect.Item): 
           return 
       if isinstance(colitem, py.test.collect.Item): 
           colitem._skipbykeyword(self.config.option.keyword)
       res = colitem.run() 
       if res is None: 
           return Passed() 
       elif not isinstance(res, (list, tuple)): 
           raise TypeError("%r.run() returned neither "
                           "list, tuple nor None: %r" % (colitem, res))
       else: 
           finish = self.startiteration(colitem, res)
           try: 
               for name in res: 
                   obj = colitem.join(name) 
                   assert obj is not None 
->                 self.runtraced(obj) 
           finally: 
               if finish: 
                   finish() 
       return res 
test/session.py - line 84
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
   def runtraced(self, colitem):
       if self.shouldclose(): 
           raise Exit, "received external close signal" 
   
       outcome = None 
       colitem.startcapture() 
       try: 
           self.start(colitem)
           try: 
               try:
                   if colitem._stickyfailure: 
                       raise colitem._stickyfailure 
->                 outcome = self.run(colitem) 
               except (KeyboardInterrupt, Exit): 
                   raise 
               except Outcome, outcome: 
                   if outcome.excinfo is None: 
                       outcome.excinfo = py.code.ExceptionInfo() 
               except: 
                   excinfo = py.code.ExceptionInfo() 
                   outcome = Failed(excinfo=excinfo) 
               assert (outcome is None or 
                       isinstance(outcome, (list, Outcome)))
           finally: 
               self.finish(colitem, outcome) 
           if isinstance(outcome, Failed) and self.config.option.exitfirst:
               py.test.exit("exit on first problem configured.", item=colitem)
       finally: 
           colitem.finishcapture()
test/session.py - line 107
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
   def run(self, colitem): 
       if self.config.option.collectonly and isinstance(colitem, py.test.collect.Item): 
           return 
       if isinstance(colitem, py.test.collect.Item): 
           colitem._skipbykeyword(self.config.option.keyword)
->     res = colitem.run() 
       if res is None: 
           return Passed() 
       elif not isinstance(res, (list, tuple)): 
           raise TypeError("%r.run() returned neither "
                           "list, tuple nor None: %r" % (colitem, res))
       else: 
           finish = self.startiteration(colitem, res)
           try: 
               for name in res: 
                   obj = colitem.join(name) 
                   assert obj is not None 
                   self.runtraced(obj) 
           finally: 
               if finish: 
                   finish() 
       return res 
test/item.py - line 64
61
62
63
64
   def run(self):
       """ setup and execute the underlying test function. """
       self._state.prepare(self) 
->     self.execute(self.obj, *self._args)
test/item.py - line 68
66
67
68
   def execute(self, target, *args):
       """ execute the given test function. """
->     target(*args)
doc/example/pytest/failure_demo.py - line 82
81
82
   def test_raises_doesnt(self):
->     raises(IOError, "int('3')")
test/raises.py - line 20
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
   def raises(ExpectedException, *args, **kwargs):
       """ raise AssertionError, if target code does not raise the expected
           exception.
       """
       assert args
       __tracebackhide__ = True 
       if isinstance(args[0], str):
           expr, = args
           assert isinstance(expr, str)
           frame = sys._getframe(1)
           loc = frame.f_locals.copy()
           loc.update(kwargs)
           #print "raises frame scope: %r" % frame.f_locals
           source = py.code.Source(expr)
           try:
->             exec source.compile() in frame.f_globals, loc
               #del __traceback__
               # XXX didn'T mean f_globals == f_locals something special?
               #     this is destroyed here ...
           except ExpectedException:
               return py.code.ExceptionInfo()
       else:
           func = args[0]
           assert callable
           try:
               func(*args[1:], **kwargs)
               #del __traceback__
           except ExpectedException:
               return py.code.ExceptionInfo()
           k = ", ".join(["%s=%r" % x for x in kwargs.items()])
           if k:
               k = ', ' + k
           expr = '%s(%r%s)' %(func.__name__, args, k)
       raise ExceptionFailure(msg="DID NOT RAISE", 
                              expr=args, expected=ExpectedException) 
code/source.py - line 196
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
   def compile(self, filename=None, mode='exec',
               flag=generators.compiler_flag, dont_inherit=0):
       """ return compiled code object. if filename is None
               invent an artificial filename which displays
               the source/line position of the caller frame.
           """
       if not filename or py.path.local(filename).check(file=0): 
           frame = sys._getframe(1) # the caller
           filename = '%s<%s:%d>' % (filename, frame.f_code.co_filename,
                                     frame.f_lineno)
       source = "\n".join(self.lines) + '\n'
       try:
           co = cpy_compile(source, filename, mode, flag)
       except SyntaxError, ex:
           # re-represent syntax errors from parsing python strings
           msglines = self.lines[:ex.lineno]
           if ex.offset:
               msglines.append(" "*ex.offset + '^')
           msglines.append("syntax error probably generated here: %s" % filename)
           newex = SyntaxError('\n'.join(msglines))
           newex.offset = ex.offset
           newex.lineno = ex.lineno
           newex.text = ex.text
           raise newex
       else:
           co_filename = MyStr(filename)
           co_filename.__source__ = self
->         return py.code.Code(co).new(rec=1, co_filename=co_filename) 
code/code.py - line 39
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
   def new(self, rec=False, **kwargs): 
       """ return new code object with modified attributes. 
               if rec-cursive is true then dive into code 
               objects contained in co_consts. 
           """ 
       names = [x for x in dir(self.raw) if x[:3] == 'co_']
       for name in kwargs: 
           if name not in names: 
               raise TypeError("unknown code attribute: %r" %(name, ))
       if rec: 
           newconstlist = []
           co = self.raw
           cotype = type(co)
           for c in co.co_consts:
               if isinstance(c, cotype):
                   c = self.__class__(c).new(rec=True, **kwargs) 
               newconstlist.append(c)
->         return self.new(rec=False, co_consts=tuple(newconstlist), **kwargs) 
       for name in names:
           if name not in kwargs:
               kwargs[name] = getattr(self.raw, name)
       return py.std.new.code(
                kwargs['co_argcount'],
                kwargs['co_nlocals'],
                kwargs['co_stacksize'],
                kwargs['co_flags'],
                kwargs['co_code'],
                kwargs['co_consts'],
                kwargs['co_names'],
                kwargs['co_varnames'],
                kwargs['co_filename'],
                kwargs['co_name'],
                kwargs['co_firstlineno'],
                kwargs['co_lnotab'],
                kwargs['co_freevars'],
                kwargs['co_cellvars'],
       )