diff options
author | Aneesh Durg <aneeshdurg17@gmail.com> | 2025-04-24 18:41:01 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-24 18:41:01 (GMT) |
commit | c7a7aa9a57c25ef2666f7dbf62edab882747af6b (patch) | |
tree | 9758b57d19fba1afad204b244eb5c0154996bd7c /Lib/test/test_cprofile.py | |
parent | e1c09fff054ebcb90e72bba25ef7332bcabec92b (diff) | |
download | cpython-c7a7aa9a57c25ef2666f7dbf62edab882747af6b.zip cpython-c7a7aa9a57c25ef2666f7dbf62edab882747af6b.tar.gz cpython-c7a7aa9a57c25ef2666f7dbf62edab882747af6b.tar.bz2 |
gh-132737: Support profiling modules that require __main___ (#132738)
Diffstat (limited to 'Lib/test/test_cprofile.py')
-rw-r--r-- | Lib/test/test_cprofile.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/Lib/test/test_cprofile.py b/Lib/test/test_cprofile.py index b46edf6..192c8ea 100644 --- a/Lib/test/test_cprofile.py +++ b/Lib/test/test_cprofile.py @@ -5,8 +5,10 @@ import unittest # rip off all interesting stuff from test_profile import cProfile +import tempfile +import textwrap from test.test_profile import ProfileTest, regenerate_expected_output -from test.support.script_helper import assert_python_failure +from test.support.script_helper import assert_python_failure, assert_python_ok from test import support @@ -154,6 +156,19 @@ class TestCommandLine(unittest.TestCase): self.assertGreater(rc, 0) self.assertIn(b"option -s: invalid choice: 'demo'", err) + def test_profile_script_importing_main(self): + """Check that scripts that reference __main__ see their own namespace + when being profiled.""" + with tempfile.NamedTemporaryFile("w+", delete_on_close=False) as f: + f.write(textwrap.dedent("""\ + class Foo: + pass + import __main__ + assert Foo == __main__.Foo + """)) + f.close() + assert_python_ok('-m', "cProfile", f.name) + def main(): if '-r' not in sys.argv: |