diff options
author | Anthony Sottile <asottile@umich.edu> | 2020-10-18 20:48:31 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-18 20:48:31 (GMT) |
commit | 3c0ac18504cfeed822439024339d5717f42bdd66 (patch) | |
tree | 5856fb42353bd419b9c39f6d2790dec194f3d5fc /Lib/test | |
parent | b81c833ab51fb7d7f0f8eaace37f60ef7455aa85 (diff) | |
download | cpython-3c0ac18504cfeed822439024339d5717f42bdd66.zip cpython-3c0ac18504cfeed822439024339d5717f42bdd66.tar.gz cpython-3c0ac18504cfeed822439024339d5717f42bdd66.tar.bz2 |
bpo-40492: Fix --outfile with relative path when the program changes it working dir (GH-19910)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_profile.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/Lib/test/test_profile.py b/Lib/test/test_profile.py index 738be85..1bdf30a 100644 --- a/Lib/test/test_profile.py +++ b/Lib/test/test_profile.py @@ -7,7 +7,7 @@ import os from difflib import unified_diff from io import StringIO from test.support import run_unittest -from test.support.os_helper import TESTFN, unlink +from test.support.os_helper import TESTFN, unlink, temp_dir, change_cwd from contextlib import contextmanager import profile @@ -112,6 +112,20 @@ class ProfileTest(unittest.TestCase): assert_python_ok('-m', self.profilermodule.__name__, '-m', 'timeit', '-n', '1') + def test_output_file_when_changing_directory(self): + with temp_dir() as tmpdir, change_cwd(tmpdir): + os.mkdir('dest') + with open('demo.py', 'w') as f: + f.write('import os; os.chdir("dest")') + + assert_python_ok( + '-m', self.profilermodule.__name__, + '-o', 'out.pstats', + 'demo.py', + ) + + self.assertTrue(os.path.exists('out.pstats')) + def regenerate_expected_output(filename, cls): filename = filename.rstrip('co') |