hgrif / pytest-exercises

pytest exercises

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pytest exercises

Exercises for the pytest presentation. Inspired by Improve Your Python: Understanding Unit Testing.

Setup

  • Clone the repo and cd into it

  • Setup a conda or virtualenv virtual environment.

conda virtual environment

  • Install the conda virtual environment from environment.yml
$ conda env create --file environment.yml
  • Activate the virtual environment
$ source activate pytest-presentation

virtualenv virtual environment

  • 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

Using primes

  • Install primes in editable mode (alternatively use python 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()

Exercises

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

About

pytest exercises

License:Apache License 2.0


Languages

Language:Python 100.0%