Exercises for the pytest presentation. Inspired by Improve Your Python: Understanding Unit Testing.
-
Clone the repo and
cd
into it -
Setup a conda or virtualenv virtual environment.
- Install the conda virtual environment from
environment.yml
$ conda env create --file environment.yml
- Activate the virtual environment
$ source activate pytest-presentation
- Create a new virtual environment called
pytest-presentation
$ virtualenv pytest-presentation
- Activate the virtual environment
$ source pytest-presentation/bin/activate
- Install the requirements from
requirements.txt
$ pip install --requirement requirements.txt
- Install
primes
in editable mode (alternatively usepython setup.py develop
):
$ pip install --editable .
- Check that you can use
primes
and exit Python:
$ python
Python 3.6.0rc1 | packaged by conda-forge | (default, Dec 7 2016, 22:57:23)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.54)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from primes import utils
>>> utils.is_prime(5)
True
>>> exit()
The exercises are in tests/test_utils.py
, read the code for explanations and exercises.
- Exercise 1 & 2: pytest basics
- Exercise 3: fixtures
- Exercise 4: checking for errors
Run all tests with
$ pytest tests/
Run a single test with
$ pytest tests/test_utils.py::test_find_next_prime