QA/Execution/Web Testing/Automation/Virtual Environments

From MozillaWiki
Jump to navigation Jump to search

Virtual environments are isolated Python environments. They allow freedom to install specific versions of dependencies without affecting the global site-packages. They also make it easy to throw away a 'broken' environment and start again. If you need further information regarding virtual environments, please see the virtualenvwrapper documentation.

Install virtualenvwrapper

  1. Install virtualenvwrapper:
  2. sudo pip install virtualenvwrapper
  3. Add the following to your ~/.bash_profile:
  4. export WORKON_HOME=$HOME/.virtualenvs source /usr/local/bin/virtualenvwrapper.sh
  5. Refresh your profile:
  6. source ~/.bash_profile

Create a virtual environment for WebQA

   mkvirtualenv webqa

Switch to the WebQA virtual environment

   workon webqa

You can leave the virtual environment by typing

   deactivate

Installation on Windows

Exception: use 32-bit version of the setuptools even if your operating system is 64-bit otherwise it fails to find the Python installation.

PIP Installation

  1. Install the 32-bit version of SetupTools using the provided .exe installer:
  2. http://pypi.python.org/pypi/setuptools#files
  3. Add the Scripts directory to your System Variables path:
  4. C:\Python26\Scripts
  5. Download the last pip version and uncompress it:
  6. http://pypi.python.org/pypi/pip#downloads
  7. In your cmd prompt, go to the uncompressed pip directory and run:
  8. python setup.py install
  9. Now you can install packages using pip on Win.
  10. : pip install <package name>

Virtualenvwrapper Installation and Usage

  1. From the cmd prompt install pip:
  2. pip install virtualenvwrapper-win
  3. Set your environment variable:
  4. WORKON_HOME = C:\Python27\Scripts:
  5. You can now create virtualenvs:
  6. mkvirtualenv <name of the environment>