Unittest mode is a minor mode enabling running python unit tests within emacs. It is intended to be used alongside python-mode in emacs.
The mode is distributed as a pack for emacs-live. To install it as an emacs-live pack, add this to your .emacs-live.el
file:
(live-add-packs '("/path/to/unittest-pack"))
Alternatively, to install without emacs-live, put unittest.el
on you emacs load path and add the following to the init file:
(require 'unittest)
(add-hook 'python-mode-hook 'unittest-mode)
The folling commands are available:
C-x t r
executesunittest-execute-current-file
- Executes the file for the current buffer with
python -u <FILE_PATH>
- Executes the file for the current buffer with
C-x t m
executesunittest-execute-current-module
- Executes the module for the current buffer with
python -u -m <DOTTED_MODULE_NAME>
- The module name is determined by walking up the filesystem tree until a
setup.py
file is found. - The last module executed in this way is recorded in the
custom
variableunittest-last-executed-module
- Executes the module for the current buffer with
C-x t l
executesunittest-execute-last-module
- Executes the last module (stored in the
custom
variableunittest-last-executed-module
)
- Executes the last module (stored in the
C-x t f
executesunittest-run-test-case
- Executes the test file for the current buffer
python -u <TEST_FILE_PATH>
- If the current file name starts with
test_
, run that file, otherwise attempt to run a file name<DIRNAME>/tests/test_<FILENAME>
. If this file doesn't exist, it fails.
- Executes the test file for the current buffer
C-x t t
executesunittest-run-tests-in-directory
- Prompts for a directory in which to execute
python -u -m unittest discover
- The default directory is the direcory of the first
setup.py
found when walking up the filesystem tree.
- Prompts for a directory in which to execute
C-x t d
executesunittest-run-tests-in-current-directory
- Executes
python -u -m unittest discover
in the direcory of the current buffer's file.
- Executes
To use this in Windows, you need to customize
the the unittest-shell-exec
variable to have the (exact) value of cmd /S /C
. This will make scripts and tests execute under a cmd.exe subshell, and set up unittest.el
to correctly quote paths with space, and cmd.exe to correctly parse the quoting.
- Changed repository structure to that of an emacs-live pack
- Added
customize
options
- unittest-run-tests-command
- unittest-discover-tests-command
- unittest-discover-module
- unittest-run-tests-directory
- Added inferior-python-mode to python-exec-mode
- Reverted to compilation-mode derived mode for executing modules
- Use comint-mode for python-exec