[TIP] testing setuptools-related code

Andrea Crotti andrea.crotti.0 at gmail.com
Mon Jan 23 09:55:11 PST 2012

On 01/20/2012 04:38 PM, Andrea Crotti wrote:
> Just on this topic, suppose I want to activate silently virtualenvs if 
> they exist,
> I thought to this possible solution.
> - start a python script with the standard python interpreter
> - lookup the project virtualenv, and create it if it doesn't exist
> - run another subprocess which is actually what I want with the
>   virtualenv interpreter, forking or substituting my original process
> Makes sense?
> Only the last part seems a bit tricky, if I just substitute the 
> python_executable
> at run-time I'm not sure it might be enough..

I'm glad to say that this idea above actually worked..
What I do is to take the same option of the actual script, then activate
or generate a virtualenv and run the other script (as the code below shows).

Now, however, what is the best way of running unit tests?
I think I can at least install nose in each virtualenv and run it with 
the right options,
or run the virtualenv python interpreter passing my own nose wrapper, which
one would be better?

def run_virtualenv(project):
     # now set the right executable
     ppath = path.abspath(project)
     venv_py = get_project_virtualenv(ppath)
     print("Setting the python executable to %s" % venv_py)
     dev_main = pkg_resources.resource_filename('psi.devsonly.bin', 
     cmd = [venv_py, dev_main] + sys.argv[1:] + \
       ['--no_multiversion_mode', '--use_virtualenv']
     # without any other setting just pass the control to the other script
     print("running command %s" % ' '.join(cmd))

def main():
     ns = parse_arguments()

More information about the testing-in-python mailing list