Installing pytest
Installing pytest is really simple, but first, let's take a moment to review good practices for Python development.
Note
All of the examples are for Python 3. They should be easy to adapt to Python 2 if necessary.
pip and virtualenv
The recommended practice for installing dependencies is to create a virtualenv
. A virtualenv
(https://packaging.python.org/guides/installing-using-pip-and-virtualenv/) acts like a complete separate Python installation from the one that comes with your operating system, making it safe to install the packages required by your application without risk of breaking your system Python or tools.
Now we will learn how to create a virtual environment and install pytest using pip. If you are already familiar with virtualenv
and pip, you can skip this section:
- Type this in your Command Prompt to create a
virtualenv
:
λ python -m venv .env
- This command will create a
.env
folder in the current directory, containing a full-blown Python installation. Before proceeding, you shouldactivate
thevirtualenv
:
λ source .env/bin/activate
Or on Windows:
λ .env\Scripts\activate
This will put the virtualenv
Python in front of the $PATH
environment variable, so Python, pip, and other tools will be executed from the virtualenv
, not from your system.
- Finally, to install pytest, type:
λ pip install pytest
You can verify that everything went well by typing:
λ pytest --version This is pytest version 3.5.1, imported from x:\fibo\.env36\lib\site-packages\pytest.py
Now, we are all set up and can begin!