Create a Vim + Python test environment in 1 minute

1. Add the following to vimrc

nnoremap <C-p> :!python %<CR>

2. Add the following above and below the target file

unittest


import unittest

#(Omission)

if __name__ == '__main__':
  unittest.main()

3. Write a test

Tests


class PythonTest(unittest.TestCase):
  def test_zero(self):
    self.assertEqual(0, 0)
  def test_foo(self):
    self.assertEqual("foo", "foo")
  def test_bar(self):
    self.assertEqual("foo", "foo")

4. You can run the test with Control + P with the file open in Vim

スクリーンショット 2013-07-11 23.58.44.png

5. Sample

sample


#! /usr/bin/env python
# -*- coding: utf-8 -*-

'Functions for evaluation'

def evaluate(value):
  """Function to return as is"""
  return value


import unittest

class EvaluateTest(unittest.TestCase):
  def test_evaluate(self):
    value = 1
    evaluated_value = evaluate(value)
    self.assertEqual(value,evaluated_value)

if __name__ == '__main__':
  unittest.main()

Recommended Posts

Create a Vim + Python test environment in 1 minute
Create a Python environment
Create a virtual environment with conda in Python
[Docker] Create a jupyterLab (python) environment in 3 minutes!
Create a function in Python
Create a dictionary in Python
Create a plugin to run Python Doctest in Vim (2)
Create a plugin to run Python Doctest in Vim (1)
Create a DI Container in Python
Create a Python environment on Mac (2017/4)
Create a virtual environment with Python!
Create a binary file in Python
Create a python environment on centos
Write a vim plugin in Python
Create a Kubernetes Operator in Python
Create a random string in Python
Write the test in a python docstring
Create a python environment on your Mac
Create a simple GUI app in Python
Let's create a virtual environment for Python
[Python] Create a virtual environment with Anaconda
Create a JSON object mapper in Python
[Python] Create a Batch environment using AWS-CDK
[GPS] Create a kml file in Python
Write a simple Vim Plugin in Python 3
Create a Python environment for professionals in VS Code on Windows
Create a GIF file using Pillow in Python
How to create a Python virtual environment (venv)
Ubuntu18.04.05 Creating a python virtual environment in LTS
Create a Python module
Create SpatiaLite in Python
I want to create a window in Python
Create a standard normal distribution graph in Python
How to create a JSON file in Python
Create a python3 build environment with Sublime Text3
Set up a test SMTP server in Python.
Test & Debug Tips: Create a file of the specified size in Python
virtual environment in python
Think about building a Python 3 environment in a Mac environment
Try to set up a Vim test environment quite seriously (for Python)
[Venv] Create a python virtual environment on Ubuntu
Create a simple momentum investment model in Python
Work in a virtual environment with Python virtualenv.
Create a new page in confluence with Python
Create a datetime object from a string in Python (Python 3.3)
Create a package containing global commands in Python
Development environment in Python
Create a MIDI file in Python using pretty_midi
Create a loop antenna pattern in Python in KiCad
Create a Python execution environment on IBM i
Create a Python virtual development environment on Windows
Create a Python development environment in 10 minutes (Mac OS X + Visual Studio Code)
Create a Python image in Django without a dummy image file and test the image upload
Create a Django project and application in a Python virtual environment and start the server
Create a data collection bot in Python using Selenium
[LINE Messaging API] Create a rich menu in Python
I want to write in Python! (2) Let's write a test
Create a comfortable Python 3 (Anaconda) development environment on windows
Create a python development environment with vagrant + ansible + fabric
In Python, create a decorator that dynamically accepts arguments Create a decorator
Create a decent shell and python environment on Windows