~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-08-30 14:29:43 UTC
  • mfrom: (1963.1.3 run-subprocess)
  • Revision ID: pqm@pqm.ubuntu.com-20060830142943-5ad00084983f33ce
(jam) run_bzr_subprocess can fix the child env

Show diffs side-by-side

added added

removed removed

Lines of Context:
843
843
        profiled or debugged so easily.
844
844
 
845
845
        :param retcode: The status code that is expected.  Defaults to 0.  If
846
 
        None is supplied, the status code is not checked.
 
846
            None is supplied, the status code is not checked.
 
847
        :param env_changes: A dictionary which lists changes to environment
 
848
            variables. A value of None will unset the env variable.
 
849
            The values must be strings. The change will only occur in the
 
850
            child, so you don't need to fix the environment after running.
847
851
        """
 
852
        env_changes = kwargs.get('env_changes', {})
 
853
        def cleanup_environment():
 
854
            for env_var, value in env_changes.iteritems():
 
855
                if value is None:
 
856
                    del os.environ[env_var]
 
857
                else:
 
858
                    os.environ[env_var] = value
 
859
 
848
860
        bzr_path = os.path.dirname(os.path.dirname(bzrlib.__file__))+'/bzr'
849
861
        args = list(args)
850
 
        process = Popen([sys.executable, bzr_path]+args, stdout=PIPE, 
851
 
                         stderr=PIPE)
 
862
        process = Popen([sys.executable, bzr_path]+args,
 
863
                         stdout=PIPE, stderr=PIPE,
 
864
                         preexec_fn=cleanup_environment)
852
865
        out = process.stdout.read()
853
866
        err = process.stderr.read()
854
867
        retcode = process.wait()