mirror of
https://github.com/python/cpython.git
synced 2025-10-17 20:28:43 +00:00
gh-110722: Add PYTHON_PRESITE to import a module before site.py is run (#110769)
This commit is contained in:
parent
ab08ff7882
commit
84b7e9e3fa
8 changed files with 178 additions and 7 deletions
|
@ -515,6 +515,8 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
|
|||
}
|
||||
if Py_STATS:
|
||||
CONFIG_COMPAT['_pystats'] = 0
|
||||
if support.Py_DEBUG:
|
||||
CONFIG_COMPAT['run_presite'] = None
|
||||
if MS_WINDOWS:
|
||||
CONFIG_COMPAT.update({
|
||||
'legacy_windows_stdio': 0,
|
||||
|
@ -1818,6 +1820,22 @@ class MiscTests(EmbeddingTestsMixin, unittest.TestCase):
|
|||
self.assertEqual(refs, 0, out)
|
||||
self.assertEqual(blocks, 0, out)
|
||||
|
||||
@unittest.skipUnless(support.Py_DEBUG,
|
||||
'-X presite requires a Python debug build')
|
||||
def test_presite(self):
|
||||
cmd = [sys.executable, "-I", "-X", "presite=test.reperf", "-c", "print('cmd')"]
|
||||
proc = subprocess.run(
|
||||
cmd,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
text=True,
|
||||
)
|
||||
self.assertEqual(proc.returncode, 0)
|
||||
out = proc.stdout.strip()
|
||||
self.assertIn("10 times sub", out)
|
||||
self.assertIn("CPU seconds", out)
|
||||
self.assertIn("cmd", out)
|
||||
|
||||
|
||||
class StdPrinterTests(EmbeddingTestsMixin, unittest.TestCase):
|
||||
# Test PyStdPrinter_Type which is used by _PySys_SetPreliminaryStderr():
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue