(self)
| 642 | @unittest.skipIf(interpreter_requires_environment(), |
| 643 | 'Cannot run -I tests when PYTHON env vars are required.') |
| 644 | def test_isolatedmode(self): |
| 645 | self.verify_valid_flag('-I') |
| 646 | self.verify_valid_flag('-IEPs') |
| 647 | rc, out, err = assert_python_ok('-I', '-c', |
| 648 | 'from sys import flags as f; ' |
| 649 | 'print(f.no_user_site, f.ignore_environment, f.isolated, f.safe_path)', |
| 650 | # dummyvar to prevent extraneous -E |
| 651 | dummyvar="") |
| 652 | self.assertEqual(out.strip(), b'1 1 1 True') |
| 653 | with os_helper.temp_cwd() as tmpdir: |
| 654 | fake = os.path.join(tmpdir, "uuid.py") |
| 655 | main = os.path.join(tmpdir, "main.py") |
| 656 | with open(fake, "w", encoding="utf-8") as f: |
| 657 | f.write("raise RuntimeError('isolated mode test')\n") |
| 658 | with open(main, "w", encoding="utf-8") as f: |
| 659 | f.write("import uuid\n") |
| 660 | f.write("print('ok')\n") |
| 661 | # Use -E to ignore PYTHONSAFEPATH env var |
| 662 | self.assertRaises(subprocess.CalledProcessError, |
| 663 | subprocess.check_output, |
| 664 | [sys.executable, '-E', main], cwd=tmpdir, |
| 665 | stderr=subprocess.DEVNULL) |
| 666 | out = subprocess.check_output([sys.executable, "-I", main], |
| 667 | cwd=tmpdir) |
| 668 | self.assertEqual(out.strip(), b"ok") |
| 669 | |
| 670 | def test_sys_flags_set(self): |
| 671 | # Issue 31845: a startup refactoring broke reading flags from env vars |
nothing calls this directly
no test coverage detected