meli-lewis / python-testing-101

#NICAR18 session on Python testing

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Testing basics CircleCI token

This repo contains the files for the #NICAR18 session "Python: Writing Tests For Your Code" and the DMN's Python/Django testing brown bag.

What's in here

  • 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

Related reading

Requirements

  • Python 2 or 3

Optional

  • virtualenv or pipenv

Installation

Using pipenv

  1. Install dependencies and create a new virtual environment with pipenv:

    $ pipenv install

Using virtualenv

  1. Optional: Create a virtual environment:

    # for Python 2
    $ virtualenv venv
    # for Python 3
    $ virtualenv venv --python=python3
  2. Optional: If you created a virtual environment, step into it before install dependencies on the next step.

    $ source venv/bin/activate
  3. Install dependencies:

    $ pip install -r requirements.txt

Usage

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

About

#NICAR18 session on Python testing

License:The Unlicense


Languages

Language:Python 96.9%Language:Makefile 3.1%