class_docstr: Test venv module functionality.
class_docstr_tok: ["Test","venv","module","functionality","."]
docstr: Test upgrading an existing environment directory.
docstr_tok: ["Test","upgrading","an","existing","environment","directory","."]
code: def test_upgrade(self):
      """
      Test upgrading an existing environment directory.
      """
      # See Issue #21643: the loop needs to run twice to ensure
      # that everything works on the upgrade (the first run just creates
      # the venv).
      for upgrade in (False, True):
          builder = venv.EnvBuilder(upgrade=upgrade)
          self.run_with_capture(builder.create, self.env_dir)
          self.isdir(self.bindir)
          self.isdir(self.include)
          self.isdir(*self.lib)
          fn = self.get_env_file(self.bindir, self.exe)
          if not os.path.exists(fn):
              # diagnostics for Windows buildbot failures
              bd = self.get_env_file(self.bindir)
              print("Contents of %r:" % bd)
              print("    %r" % os.listdir(bd))
          self.assertTrue(
              os.path.exists(fn), "File %r should exist." % fn
          )
  
imports: import contextlib
  import ensurepip
  import os
  import os.path
  import pathlib
  import re
  import shutil
  import struct
  import subprocess
  import sys
  import sysconfig
  import tempfile
  from test.support import captured_stdout, captured_stderr, skip_if_broken_multiprocessing_synchronize, verbose, requires_subprocess, is_emscripten, is_wasi, requires_venv_with_pip, TEST_HOME_DIR, requires_resource, copy_python_src_ignore
  from test.support.os_helper import can_symlink, EnvironmentVarGuard, rmtree
  import unittest
  import venv
  from unittest.mock import patch, Mock
label_desc: Use image node_id 15 for calling the BasicTest obj's underlying member method code with example usage: obj.test_upgrade() without return types