python layer: new variable python-test-runner, can be nose
or pytest
This commit is contained in:
parent
95526e8627
commit
d1ecbfa6bb
|
@ -9,13 +9,14 @@
|
|||
- [Description](#description)
|
||||
- [Install](#install)
|
||||
- [Layer](#layer)
|
||||
- [Test runner](#test-runner)
|
||||
- [Anaconda dependencies](#anaconda-dependencies)
|
||||
- [Automatic buffer formatting on save](#automatic-buffer-formatting-on-save)
|
||||
- [autoflake](#autoflake)
|
||||
- [Key Bindings](#key-bindings)
|
||||
- [Inferior REPL process](#inferior-repl-process)
|
||||
- [Running Python Script in shell](#running-python-script-in-shell)
|
||||
- [Testing in Python](#testing-in-python)
|
||||
- [Testing](#testing)
|
||||
- [Refactoring](#refactoring)
|
||||
- [Other Python commands](#other-python-commands)
|
||||
- [Django](#django)
|
||||
|
@ -36,7 +37,7 @@ Features:
|
|||
- Auto-completion using [anaconda-mode][]
|
||||
- Code Navigation using [anaconda-mode][]
|
||||
- Documentation Lookup using [anaconda-mode][] and [pylookup][]
|
||||
- Test Runner using [nose.el][]
|
||||
- Test Runners using [nose.el][] or [pytest][]
|
||||
- Virtual Environment using [pyvenv][] and [pyenv][]
|
||||
- semantic mode is enabled
|
||||
- Django support via [pony-mode][]
|
||||
|
@ -53,6 +54,19 @@ To use this contribution add it to your `~/.spacemacs`
|
|||
(setq-default dotspacemacs-configuration-layers '(python))
|
||||
```
|
||||
|
||||
### Test runner
|
||||
|
||||
Both `nose` and `pytest` are supported. By default `nose` is used.
|
||||
To choose your test runner set the layer variable `python-test-runner` to
|
||||
either `nose` or `pytest`.
|
||||
|
||||
The root of the project is detected with a `.git` directory or a `setup.cfg` file.
|
||||
|
||||
```elisp
|
||||
(setq-default dotspacemacs-configuration-layers
|
||||
'((python :variables python-test-runner 'pytest)))
|
||||
```
|
||||
|
||||
### Anaconda dependencies
|
||||
|
||||
`anaconda-mode` tries to install the dependencies itself but sometimes
|
||||
|
@ -124,44 +138,7 @@ modules.
|
|||
**Note** With the universal argument <kbd>SPC u</kbd> you can enter a new
|
||||
compilation command.
|
||||
|
||||
### Testing in Python
|
||||
|
||||
`Spacemacs` uses [nose][nose] as a test runner. An improved version of
|
||||
[nose.el][nose.el] is shipped with `Spacemacs`, this version adds:
|
||||
- windows support
|
||||
- test suite support
|
||||
|
||||
The root of the project is detected with a `.git` directory or a `setup.cfg` file.
|
||||
|
||||
Test commands (start with <kbd>m t</kbd> or <kbd>m T</kbd>):
|
||||
|
||||
No Debug | Description
|
||||
---------------------|------------------------------------------------------------
|
||||
<kbd>SPC m t a</kbd> | launch all tests of the project
|
||||
<kbd>SPC m t b</kbd> | launch all tests of the current buffer (same as module)
|
||||
<kbd>SPC m t m</kbd> | launch all tests of the current module
|
||||
<kbd>SPC m t s</kbd> | launch all tests of the current suite
|
||||
<kbd>SPC m t t</kbd> | launch the current test (function)
|
||||
|
||||
Debug | Description
|
||||
---------------------|------------------------------------------------------------
|
||||
<kbd>SPC m T a</kbd> | launch all tests of the project in debug mode
|
||||
<kbd>SPC m T b</kbd> | launch all tests of the current buffer (module) in debug mode
|
||||
<kbd>SPC m T m</kbd> | launch all tests of the current module in debug mode
|
||||
<kbd>SPC m T s</kbd> | launch all tests of the current suite in debug mode
|
||||
<kbd>SPC m T t</kbd> | launch the current test (function) in debug mode
|
||||
|
||||
#### Using pytest
|
||||
|
||||
If you would rather use pytest then set `python-use-pytest` to `t` in your
|
||||
`dotspacemacs/init` function.
|
||||
|
||||
|
||||
```elisp
|
||||
(defun dotspacemacs/init ()
|
||||
(setq-default python-use-pytest t)
|
||||
)
|
||||
```
|
||||
### Testing
|
||||
|
||||
Test commands (start with <kbd>m t</kbd> or <kbd>m T</kbd>):
|
||||
|
||||
|
@ -170,6 +147,7 @@ Test commands (start with <kbd>m t</kbd> or <kbd>m T</kbd>):
|
|||
<kbd>SPC m t a</kbd> | launch all tests of the project
|
||||
<kbd>SPC m t b</kbd> | launch all tests of the current buffer (same as module)
|
||||
<kbd>SPC m t m</kbd> | launch all tests of the current module
|
||||
<kbd>SPC m t s</kbd> | launch all tests of the current suite (only with `nose`)
|
||||
<kbd>SPC m t t</kbd> | launch the current test (function)
|
||||
|
||||
Debug | Description
|
||||
|
@ -177,6 +155,7 @@ Test commands (start with <kbd>m t</kbd> or <kbd>m T</kbd>):
|
|||
<kbd>SPC m T a</kbd> | launch all tests of the project in debug mode
|
||||
<kbd>SPC m T b</kbd> | launch all tests of the current buffer (module) in debug mode
|
||||
<kbd>SPC m T m</kbd> | launch all tests of the current module in debug mode
|
||||
<kbd>SPC m T s</kbd> | launch all tests of the current suite in debug mode (only with `nose`)
|
||||
<kbd>SPC m T t</kbd> | launch the current test (function) in debug mode
|
||||
|
||||
### Refactoring
|
||||
|
@ -261,13 +240,13 @@ Manage Django with <kbd>SPC m j m</kbd>.
|
|||
<kbd>mjtt</kbd> | Run the test(s) given by `command`
|
||||
<kbd>mjtu</kbd> | Move up the traceback one level
|
||||
|
||||
|
||||
[anaconda-mode]: https://github.com/proofit404/anaconda-mode
|
||||
[pyvenv]: https://github.com/jorgenschaefer/pyvenv
|
||||
[pyenv]: https://github.com/yyuu/pyenv
|
||||
[pylookup]: https://github.com/tsgates/pylookup
|
||||
[nose]: https://github.com/nose-devs/nose/
|
||||
[nose.el]: https://github.com/syl20bnr/nose.el
|
||||
[pytest]: https://github.com/ionrock/pytest-el
|
||||
[pony-mode]: https://github.com/davidmiller/pony-mode
|
||||
[anaconda-deps]: https://github.com/proofit404/anaconda-mode/blob/master/requirements.txt
|
||||
[YAPF]: https://github.com/google/yapf
|
||||
|
|
|
@ -19,6 +19,9 @@
|
|||
(defvar python-enable-yapf-format-on-save nil
|
||||
"If non-nil, automatically format code with YAPF on save.")
|
||||
|
||||
(defvar python-test-runner 'nose
|
||||
"Test runner to use. Possible values are `nose' or `pytest'.")
|
||||
|
||||
;; Command prefixes
|
||||
|
||||
;; not supported for now
|
||||
|
|
|
@ -16,17 +16,17 @@
|
|||
;; Post extensions are loaded *after* the packages
|
||||
(setq python-post-extensions
|
||||
'(
|
||||
nose
|
||||
pylookup
|
||||
python-compile
|
||||
py-yapf
|
||||
))
|
||||
|
||||
(unless python-use-pytest
|
||||
(push 'nose python-post-extensions))
|
||||
;; Initialize the extensions
|
||||
|
||||
(defun python/init-nose ()
|
||||
(use-package nose
|
||||
:if (eq 'nose python-test-runner)
|
||||
:commands (nosetests-one
|
||||
nosetests-pdb-one
|
||||
nosetests-all
|
||||
|
|
|
@ -24,16 +24,14 @@
|
|||
pip-requirements
|
||||
pony-mode
|
||||
pyenv-mode
|
||||
pyvenv
|
||||
pytest
|
||||
python
|
||||
pyvenv
|
||||
semantic
|
||||
smartparens
|
||||
stickyfunc-enhance
|
||||
))
|
||||
|
||||
(if python-use-pytest
|
||||
(push 'pytest python-packages))
|
||||
|
||||
(defun python/init-anaconda-mode ()
|
||||
(use-package anaconda-mode
|
||||
:defer t
|
||||
|
@ -128,6 +126,7 @@
|
|||
|
||||
(defun python/init-pytest ()
|
||||
(use-package pytest
|
||||
:if (eq 'pytest python-test-runner)
|
||||
:defer t
|
||||
:commands (pytest-one
|
||||
pytest-pdb-one
|
||||
|
@ -135,20 +134,16 @@
|
|||
pytest-pdb-all
|
||||
pytest-module
|
||||
pytest-pdb-module)
|
||||
:init
|
||||
(evil-leader/set-key-for-mode 'python-mode
|
||||
"mTa" 'pytest-pdb-all
|
||||
"mta" 'pytest-all
|
||||
"mTb" 'pytest-pdb-module
|
||||
"mtb" 'pytest-module
|
||||
"mTt" 'pytest-pdb-one
|
||||
"mtt" 'pytest-one
|
||||
"mTm" 'pytest-pdb-module
|
||||
"mtm" 'pytest-module)
|
||||
:config
|
||||
(progn
|
||||
(add-to-list 'pytest-project-root-files "setup.cfg")
|
||||
)))
|
||||
:init (evil-leader/set-key-for-mode 'python-mode
|
||||
"mTa" 'pytest-pdb-all
|
||||
"mta" 'pytest-all
|
||||
"mTb" 'pytest-pdb-module
|
||||
"mtb" 'pytest-module
|
||||
"mTt" 'pytest-pdb-one
|
||||
"mtt" 'pytest-one
|
||||
"mTm" 'pytest-pdb-module
|
||||
"mtm" 'pytest-module)
|
||||
:config (add-to-list 'pytest-project-root-files "setup.cfg")))
|
||||
|
||||
(defun python/init-python ()
|
||||
(use-package python
|
||||
|
|
Loading…
Reference in a new issue