About the Project

In the evolving landscape of software development, the integration of efficient testing tools is crucial for maintaining code quality. Introducing pytest.nvim, an innovative plugin designed for the Neovim environment. This project is currently under active development, with plans for additional features to enhance its functionality. The creator is open to contributions from the community, recognizing the collaborative spirit that drives open-source projects.

Getting Started

Setting up the pytest.nvim plugin is straightforward. These instructions will guide you through the process of integrating pytest into your Neovim setup, ensuring you have a seamless experience when running tests.

Prerequisites

Before diving into the installation process, ensure that you have:

  • Neovim version 0.9.0 or later installed on your system.
  • The pytest library within your Python environment, which can be easily installed using the command: pip install pytest.

Installation

To get started, install the pytest.nvim plugin using your preferred package manager. For users of Lazyvim, add the following line to your configuration: { "richardhapb/pytest.nvim", opts = {} }. Alternatively, if you are using Packer, you can install it by using: use { "richardhapb/pytest.nvim", opt = true }. This flexibility accommodates various user preferences in managing plugins.

Usage

Once the plugin is installed, you will need to load it within your Neovim configuration. For example, include the following line: require('pytest').setup(). Afterward, you can easily run tests from the current buffer using the :Pytest command. To test the entire buffer, simply use :Pytest again.

To see the output of your tests, which defaults to showing only failed tests, you can utilize the command: :PytestOutput. For those who prefer automatic testing, you can attach the test to the current buffer, which will initiate tests upon saving any Python file using :PytestAttach. Conversely, if you wish to detach the test from the last attached buffer, the command :PytestDetach serves this purpose.

Additionally, Docker support is on the horizon. Users will be able to enable it with :PytestEnableDocker and disable it via :PytestDisableDocker.

Default Keybindings

The plugin comes equipped with several default keybindings that streamline your workflow:

  • <leader>TT - Run pytest for the current file (normal mode)
  • <leader>Ta - Attach pytest to the current buffer (normal mode)
  • <leader>Td - Detach pytest from the current buffer (normal mode)

While these default settings are functional out of the box, they can be customized in your configuration file to better suit your needs.

For instance, if you desire to enable Docker support, you can configure it as follows:

require 'pytest'.setup {  docker = { enabled = false, container = 'app-1', docker_path = '/usr/src/app', docker_path_prefix = 'app', enable_docker_compose = false, docker_compose_file = 'docker-compose.yml', docker_compose_service = 'app', }, }

This configuration allows for granular control over how pytest interacts with Docker, enhancing the testing process.

Options and Customization

The pytest.nvim plugin is designed with flexibility in mind. Users can define functions as settings, enabling dynamic configurations based on their project structure. For example:

require 'pytest'.setup { docker = { enabled = function() return vim.fn.getcwd():match('.*/(.*)$') == 'work' end, }, }

This feature allows for more complex setups, catering to various development environments and workflows.

Features

The plugin boasts several key features, including:

  • Robust Docker integration
  • Path mapping from Docker Compose files
  • Support for attaching and detaching tests seamlessly
  • Centralized user interface for managing test results
  • Customizable arguments for the pytest command

By parsing error lines from JSON output, pytest.nvim enhances the developer's ability to identify issues effectively, rather than relying solely on standard output.

Contributing

Contributions from the community play a vital role in the success of open-source projects. If you have suggestions to improve pytest.nvim, consider forking the repository and creating a pull request. Alternatively, you can open an issue tagged with “enhancement.” Your involvement can make a significant difference in shaping the future of this plugin.

Lastly, if you appreciate the work done on this project, don’t forget to give it a star on its repository. Your support is invaluable!