~/Blog

Brandon Rozek

Photo of Brandon Rozek

PhD Student @ RPI studying Automated Reasoning in AI and Linux Enthusiast.

Automate Python Test Suites with Tox

Published on

Updated on

Warning: This post has not been modified for over 2 years. For technical posts, make sure that it is still relevant.

Tox is a great project where you can automate your testing using virtual environments.

First install tox

pip install tox

I like to write my tests in Python’s native unittest format. Tests should be stored in a tests directory.

I then combine it with the coverage library to tell me how much of my code that my test cases cover. To quickly insert my personal opinion, I never aim for 100% test coverage since there’s typically overhead in maintaining that.

This all gets described in a tox.ini file. This file should live in the same directory as your setup.py

[tox]
envlist =
    py38

[testenv]
deps = coverage
commands =
    coverage run --source=tests,library -m unittest discover tests
    coverage report -m
Reply via Email Buy me a Coffee
Was this useful? Feel free to share: Hacker News Reddit Twitter

Published a response to this? :