[3.11] Fix test_py_compile with -O mode (GH-115345) (GH-115670)

(cherry picked from commit 07ef9d86a5)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
Miss Islington (bot) 2024-02-19 18:45:56 +01:00 committed by GitHub
parent d4915220e7
commit 55b9633316
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -227,7 +227,8 @@ class PyCompileCLITestCase(unittest.TestCase):
def setUp(self):
self.directory = tempfile.mkdtemp()
self.source_path = os.path.join(self.directory, '_test.py')
self.cache_path = importlib.util.cache_from_source(self.source_path)
self.cache_path = importlib.util.cache_from_source(self.source_path,
optimization='' if __debug__ else 1)
with open(self.source_path, 'w') as file:
file.write('x = 123\n')
@ -249,6 +250,7 @@ class PyCompileCLITestCase(unittest.TestCase):
return script_helper.assert_python_failure('-m', 'py_compile', *args)
def test_stdin(self):
self.assertFalse(os.path.exists(self.cache_path))
result = self.pycompilecmd('-', input=self.source_path)
self.assertEqual(result.returncode, 0)
self.assertEqual(result.stdout, b'')