Skip to content

Instantly share code, notes, and snippets.

@christophermark
Last active August 29, 2015 14:14
Show Gist options
  • Save christophermark/549a088b8c120b701db9 to your computer and use it in GitHub Desktop.
Save christophermark/549a088b8c120b701db9 to your computer and use it in GitHub Desktop.
A full Python testing stack

So you want to test?

A breakdown of a full Python testing stack

Updated January, 2015
Below is a layer-by-layer breakdown of how I test my Python projects, starting with my Github repository and ending with the test files themselves.

Layer 1: Travis-CI

www.Travis-CI.org

Testing begins with Travis-CI, which hooks into your Github repository to automatically run tests on pull requests and current production branches. It provides a nice visual representation of when tests are failing and a decent overview of all the tests scheduled to run. Travis integration is run through a .travis.yml file in the main project repository. Although Travis is itself a capable test runner, it is important to maintain the ability to run tests locally without having to submit a pull request to test. That's why we'll be using test runners such as tox as described below.

2. Setup.py (using setuptools)

Tests are run [locally] by running the command python setup.py test.

This setup.py file serves two purposes:

  • Metadata about the project (author, name, etc. in setup() method)
  • Requred for using Tox.
  • (Optional) You can run tox through the command setup.py test, if desired. We choose to do this.

In summary:
You ALWAYS need a setup.py file to run tests. And to provide metadata.
You can optionally run tests directly from Tox (command: tox) instead of going through python setup.py test

Although it seems

test

setup(
	name='robin-relay-tools',
	version='1.0',
	description='Tools for the setup and testing of Robin hardware',
	author='Chris Mark',
	platforms='any',
	tests_require=['tox'],
    cmdclass = {'test': Tox},
    author_email='chris@robinpowered.com',
    )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment