Try to set up a Vim test environment quite seriously (for Python)

Overview

--Until now, UnitTest has been executed by vim-quickrun or after returning with C-Z and hitting the terminal. --Currently, it's hard to do test-driven development with Vim. ――It's time to create test settings. --By the way, it's Python's Unit Test

current problem

  1. :QuickRun --QuickRun can only run the entire test. I think (because I'm not a test runner) ――It may be possible if you do your best. ――It's hard to do the whole execution many times for a long test or a slow test. I want to do just one method or something quickly.
  2. Terminal execution ――It's tiresome to go back to the terminal. --To run per-class or per-method tests in the terminal, you have to hit the package hierarchy. It's hard. ――I want to fly to Red with QuickFix. Seeing terminal errors-> Vim back-> Returning to terminal error seeing is stupid.
  3. :make --Make can do anything for the time being. (I confirmed that I could do it roughly, but I did not say that I could do it) ――The setting seems to be difficult. Do you write settings for builtin unittest, djangotest, nose, pytest, etc. It's hard.

Target

Make Vim's test environment feel good. In particular...

--What you can do on Vim --Test class / method unit execution is possible --You can output the result to QuickFix and jump ――It can be handled to some extent even if the number of target languages / frameworks increases. --You can specify test execution options (if this is not possible, you will eventually return to make) --Asynchronous execution

Investigation

For the time being. Check through the test plugins. Type test in the search form of Vim Awesome. Then I realize that there are surprisingly few solutions with existing plugins. There weren't many test plugins themselves ... Is there a lot of people solving it with make?

vim-test A plugin called vim-test came out at the top. Besides, pytest.vim and [vim-python-test-runner](https://github.com/jarrodctaylor/vim-python-test- There were runners), but in the end only vim-test met the requirements.

Implementation of measures

Although it is a rough investigation, measures are started for the time being

Introduced vim-test

Insco vim-test. My interpretation is that English is inconvenient

--Test wrapper for various particle sizes --Supports various languages and frameworks --No dependent plugins for test execution only --You don't have to set that much ――You can choose the runner to run. It will be detected automatically without explicitly selecting it. --You can also specify CLI options

It was a plug-in that was easy to install and had a lot of customization. I remember ALE.

Put it in for the time being. Dakpawa dein.vim. By the way, I manage all plugins in toml.

[[plugins]]
repo = 'janko-m/vim-test'

There are 5 types of test execution methods as follows. For more information here

Make a test and run it. Execute : TestFile Screen Shot 2017-08-12 at 3.55.53.png I was able to execute it. But QuickFix isn't, and you can't scroll, so you can't follow the entire error message. This is meaningless.

Quick Fix display

Read the vim-test README. Apparently, if you want to output to QuickFix, you need another plugin as a test runner. Therefore, the author recommends Dispatch.vim.

Introduced Dispatch.vim

When I looked it up, it was a plug-in that was pretty cool. In short, it's a plugin for asynchronous execution of the compiler, but it splits the execution process into screens and displays it. Moreover, it is a kind specification that automatically detects the execution environment and divides the screen without permission. In my case it's tmux & neovim. I created a tmux pane without permission, closed it when I finished, and put out QuickFix.

Dein.vim again. Also, explicitly set Dispatch.vim as a runner on the vim-test side.

[[plugins]]
repo = 'tpope/vim-dispatch'

[[plugins]]
repo = 'janko-m/vim-test'
depends = ['vim-dispatch']
hook_add = '''
let g:test#strategy = 'dispatch'
'''

Execute Mokkai : TestFile. Screen Shot 2017-08-12 at 4.28.18.png QuickFix is displayed safely. However, errorformat was not applied to QuickFix. You can't jump with this.

Python compiler settings

For the time being, the error format of Python has been set as follows, but it seems that this is useless.

augroup MyErrorFormat
    autocmd!
    autocmd BufNewFile,BufRead *.py
        \ setlocal errorformat=%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m
augroup END

Looking at the help of Dispatch.vim, it seems that errorformat will have the default applied if there is no compiler plugin to run.

:Dispatch[!] [options] {program} [arguments]
                        Find a compiler plugin that sets 'makeprg' to
                        {program} and use its 'errorformat' to dispatch a
                        |:Make| for the given {program} and [arguments].  If
                        no compiler plugin is found, the generic format
                        %+I%.%# is used.

I wondered what it was and looked it up, and found a plug-in that looked like it.

Introducing vim-compiler-python

vim-compiler-python seems to be a plug-in that looks at the source and manages the compiler settings at the time of : make. I don't think it's really good, but I'm exhausted so I'll check it later.

Dein.vim again.

[[plugins]]
repo = 'aliev/vim-compiler-python'

Execute Mokkai : TestFile. Screen Shot 2017-08-12 at 4.55.24.png

I finally reached the level I was looking for. vimrc I haven't messed with it, but I'm tired.

Setting summary

The setting added this time looks like this. To be honest, I still have test option settings and key binding settings, but I'll do that again next time.

[[plugins]]
repo = 'tpope/vim-dispatch'

[[plugins]]
repo = 'janko-m/vim-test'
depends = ['vim-dispatch']
hook_add = '''
let g:test#strategy = 'dispatch'
'''

[[plugins]]
repo = 'aliev/vim-compiler-python'

Recommended Posts

Try to set up a Vim test environment quite seriously (for Python)
How to set up a Python environment using pyenv
Set up a test SMTP server in Python.
Set up a Python development environment on Marvericks
Set up a Python development environment with Sublime Text 2
Set Up for Mac (Python)
Set up a Python development environment with Visual Studio Code
Try to bring up a subwindow with PyQt5 and Python
How to set up WSL2 on Windows 10 and create a study environment for Linux commands
I want to set up a GUI development environment with Python or Golang on Mac
Build and test a CI environment for multiple versions of Python
Try using virtualenv, which can build a virtual environment for Python
Try to create a python environment with Visual Studio Code & WSL
Let's create a virtual environment for Python
I want to build a Python environment
[Mac] Building a virtual environment for Python
Building a Python development environment for AI development
Add a Python virtual environment to VSCode
Building a virtual environment for Mayavi dedicated to Python 3.6, Anaconda, Spyder users
Things to watch out for when creating a Python environment on a Mac
Send mail with mailx to a dummy SMTP server set up with python.
Try to solve a set problem of high school math with Python
Introduction and usage of Python bottle ・ Try to set up a simple web server with login function
Set up a simple HTTPS server in Python 3
Try to calculate a statistical problem in Python
How to create a Python virtual environment (venv)
I want to create a nice Python development environment for my new Mac
Try to draw a life curve with python
Try to make a "cryptanalysis" cipher with Python
[Cloudian # 10] Try to generate a signed URL for object publishing in Python (boto3)
Try to calculate RPN in Python (for beginners)
Set up python Tornado environment on raspbian jessie
Commands for creating a python3 environment with virtualenv
Procedure for creating a Python quarantine environment (venv environment)
Try to make a dihedral group with Python
How to set up a local development server
Set up a simple SMTP server in Python
A memo for creating a python environment by a beginner
Set up TinyGo development environment for VS Code
How to set up a Google Colab environment with Coursera's advanced machine learning courses
I want to set up a mock server for python-flask in seconds using swagger-codegen.
Script to easily create a client device environment for AWS IoT (Python v2 version)
How to set the development environment for each project with VSCode + Python extension + Miniconda
From setting up Raspberry Pi to installing Python environment
Building a Python environment for pyenv, pyenv-virtualenv, Anaconda (Miniconda)
Building a Docker working environment for R and Python
(Python) Try to develop a web application using Django
I want to write in Python! (2) Let's write a test
Build a python environment for each directory with pyenv-virtualenv
Try searching for a million character profile in Python
Create a plugin to run Python Doctest in Vim (1)
[Introduction to python] A high-speed introduction to Python for busy C ++ programmers
How to build a Django (python) environment on docker
Procedure for building a CDK environment on Windows (Python)
For those who want to write Python with vim
How to build a development environment for TensorFlow (1.0.0) (Mac)
Write code to Unit Test a Python web app
Building a Python environment for programming beginners (Mac OS)
How to set up and compile your Cython environment
Memo for building a machine learning environment using Python
Setting up Jupyter Lab in a Python 3.9 venv environment