[issue9914] trace/profile conflict with the use of sys.modules[__name__]

Alexander Belopolsky report at bugs.python.org
Tue Sep 21 20:17:45 CEST 2010

New submission from Alexander Belopolsky <belopolsky at users.sourceforge.net>:

The main() method of trace and profile modules attempt to emulate the environment in which traced code runs when invoked directly, but it fails in several respects.   The specific problem which is the subject of this issue is that while __name__ is set to '__main__' in code globals, sys.modules['__main__'] still point to the trace/profile module.

Among other problems, this conflicts, with a popular idiom used in regression test scripts:


For example,

$ python -m trace -c -C trace.d Lib/test/test_optparse.py 

Ran 0 tests in 0.001s


No tests are ran because run_unittests() looks for test case classes in the trace module and finds none.

This is related to #9323, so I am merging in the nosy list.  See also r83393.

assignee: belopolsky
components: Library (Lib)
messages: 117090
nosy: belopolsky, eli.bendersky, ezio.melotti, flox, georg.brandl
priority: normal
severity: normal
status: open
title: trace/profile conflict with the use of sys.modules[__name__]
type: behavior
versions: Python 3.2

Python tracker <report at bugs.python.org>

More information about the Python-bugs-list mailing list