@@ -235,6 +235,18 @@ def add_operator(a, b):
235235 return a + b
236236 ''' ))
237237
238+ # Note: this can't be profiled because `test_mod.more-utils` is not
239+ # a valid dotted path
240+ (temp_dpath / 'test_mod/dev-utils.py' ).write_text (ub .codeblock (
241+ '''
242+ """
243+ Just imagine that the file contains some dev tools.
244+ """
245+
246+ def publish_pkg():
247+ pass
248+ ''' ))
249+
238250 (temp_dpath / 'test_mod/submod1.py' ).write_text (ub .codeblock (
239251 '''
240252 from test_mod.util import add_operator
@@ -332,7 +344,8 @@ def test_autoprofile_script_with_module():
332344 assert 'Function: main' in raw_output
333345
334346
335- def test_autoprofile_module ():
347+ @pytest .mark .parametrize ('static_resolution' , [True , False ])
348+ def test_autoprofile_module (static_resolution ):
336349 """
337350 Test that every function in a file is profiled when autoprofile is
338351 enabled.
@@ -342,11 +355,14 @@ def test_autoprofile_module():
342355
343356 script_fpath = _write_demo_module (temp_dpath )
344357
345- # args = [sys.executable, '-m', 'kernprof', '--prof-imports',
346- # '-p', 'script.py', '-l', os.fspath(script_fpath)]
347358 args = [sys .executable , '-m' , 'kernprof' , '-p' , 'test_mod' , '-l' ,
348359 os .fspath (script_fpath )]
349- proc = ub .cmd (args , cwd = temp_dpath , verbose = 2 )
360+ env = dict (os .environ )
361+ if static_resolution :
362+ env ['LINE_PROFILER_STATIC_ANALYSIS' ] = '1'
363+ else :
364+ env .pop ('LINE_PROFILER_STATIC_ANALYSIS' , None )
365+ proc = ub .cmd (args , cwd = temp_dpath , env = env , verbose = 2 )
350366 print (proc .stdout )
351367 print (proc .stderr )
352368 proc .check_returncode ()
0 commit comments