File tree Expand file tree Collapse file tree 2 files changed +21
-5
lines changed Expand file tree Collapse file tree 2 files changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -175,10 +175,8 @@ def main():
175
175
if len (args ) > 0 :
176
176
if options .module :
177
177
code = "run_module(modname, run_name='__main__')"
178
- globs = {
179
- 'run_module' : runpy .run_module ,
180
- 'modname' : args [0 ]
181
- }
178
+ globs = globals ().copy ()
179
+ globs .update ({"run_module" : runpy .run_module , "modname" : args [0 ]})
182
180
else :
183
181
progname = args [0 ]
184
182
sys .path .insert (0 , os .path .dirname (progname ))
Original file line number Diff line number Diff line change 5
5
6
6
# rip off all interesting stuff from test_profile
7
7
import cProfile
8
+ import tempfile
9
+ import textwrap
8
10
from test .test_profile import ProfileTest , regenerate_expected_output
9
- from test .support .script_helper import assert_python_failure
11
+ from test .support .script_helper import assert_python_failure , assert_python_ok
10
12
from test import support
11
13
12
14
@@ -155,6 +157,22 @@ def test_sort(self):
155
157
self .assertIn (b"option -s: invalid choice: 'demo'" , err )
156
158
157
159
160
+ class TestProfilingScript (unittest .TestCase ):
161
+ def test_profile_script_importing_main (self ):
162
+ """Check that scripts that reference __main__ see their own namespace
163
+ when being profiled."""
164
+ with tempfile .NamedTemporaryFile ("w+" ) as f :
165
+ f .write (textwrap .dedent ("""\
166
+ class Foo:
167
+ pass
168
+
169
+ import __main__
170
+ assert Foo == __main__.Foo
171
+ """ ))
172
+ f .flush ()
173
+ assert_python_ok ('-m' , "cProfile" , f .name )
174
+
175
+
158
176
def main ():
159
177
if '-r' not in sys .argv :
160
178
unittest .main ()
You can’t perform that action at this time.
0 commit comments