gh-73965: New environment variable PYTHON_HISTORY (#13208)

It can be used to set the location of a .python_history file

---------

Co-authored-by: Levi Sabah <0xl3vi@gmail.com>
Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
This commit is contained in:
Zackery Spytz 2024-01-06 22:30:12 -08:00 committed by GitHub
parent 541c5dbb81
commit f19b93fce0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 50 additions and 3 deletions

View file

@ -7,6 +7,7 @@ executing have not been removed.
import unittest
import test.support
from test import support
from test.support.script_helper import assert_python_ok
from test.support import os_helper
from test.support import socket_helper
from test.support import captured_stderr
@ -338,6 +339,19 @@ class HelperFunctionsTests(unittest.TestCase):
mock_addsitedir.assert_not_called()
self.assertFalse(known_paths)
def test_gethistoryfile(self):
filename = 'file'
rc, out, err = assert_python_ok('-c',
f'import site; assert site.gethistoryfile() == "{filename}"',
PYTHON_HISTORY=filename)
self.assertEqual(rc, 0)
# Check that PYTHON_HISTORY is ignored in isolated mode.
rc, out, err = assert_python_ok('-I', '-c',
f'import site; assert site.gethistoryfile() != "{filename}"',
PYTHON_HISTORY=filename)
self.assertEqual(rc, 0)
def test_trace(self):
message = "bla-bla-bla"
for verbose, out in (True, message + "\n"), (False, ""):