This repo contains the files for the #NICAR18 session "Python: Writing Tests For Your Code" and the DMN's Python/Django testing brown bag.
- dumbfunctions.py: This is just some sample code, which we'll exercise with our tests
- tests.py: A Python module with two "test cases"; running this file will run our tests
- circle.yml: A configuration file for Circle CI, which is wired to this repo as a continuous integration service
- Unit testing framework, official Python docs
- Mock object library, official Python docs
- Testing Your Code, The Hitchiker's Guide to Python
- Testing in Django, official Django docs
- Python 2 or 3
Optional
virtualenv
orpipenv
-
Install dependencies and create a new virtual environment with
pipenv
:$ pipenv install
-
Optional: Create a virtual environment:
# for Python 2 $ virtualenv venv
# for Python 3 $ virtualenv venv --python=python3
-
Optional: If you created a virtual environment, step into it before install dependencies on the next step.
$ source venv/bin/activate
-
Install dependencies:
$ pip install -r requirements.txt
The below should be run in your virtual environment if you're using one. For example, you should run pipenv shell
before running the below if you're using pipenv
.
To run tests:
$ python tests.py
To run tests and check test coverage:
$ coverage run --omit='.venv/**/*.py,venv/**/*.py,tests.py' tests.py
To view coverage information in the console:
$ coverage report
To see an HTML page with coverage information:
$ coverage html # needs to run each time you do "coverage run"
$ open htmlcov/index.html