OpenStack projects have a relatively well defined testing interface
that uses tox
and testrepository
.
This is a mode to make testing using those be easily available inside of emacs. This reuses the compile infrastructure in emacs and is based upon nosemacs that does this same functionality for nose.
Add the following to your .emacs configuration:
(require 'stacktest) ;; optionally enable for all python files (add-hook 'python-mode-hook 'stacktest-mode)
From within a python file you can run any of the following:
- M-x stacktest-one : runs the current test function your cursor is in
- M-x stacktest-debug-one : runs the current test function your cursor is in with OS_DEBUG=True (turns on debug logging)
- M-x stacktest-pdb-one : runs the current test function your cursor is in pdb
- M-x stacktest-module : runs all the tests in the current file
- M-x stacktest-all : runs a full
tox
run in an emacs buffer - M-x stacktest-target : prompts for and runs a specific
tox
environment - M-x stacktest-again : rerun the last test run
You can bind these to more convenient keys. The various modes are extremely useful when iterating on test development. The compilation buffer is annotated so that failure points are clickable back into the code in question.
This also works over tramp if you are using ssh as your transport, through the magic of awesomeness.
A successful stacktest-one run (M-x stacktest-one from the shown cursor possition)
A failed stacktest-one run. The filenames listed in the traceback are linked elements that will open those files at those lines.
When running in -one or -module mode the testing skips tox / testr
entirely and just uses subunit.run (if subunit-trace is available) or
testtools.run from the .tox/py27 directory. This means we assume
you've run tox -e py27
at least once before running this.
Things that would be nice to have (PRs welcomed)
- further enhance the compilation buffer regexp to make it easier to understand at a glance
- menu available when stacktest-mode enable