Skip to content

Conversation

Shai-tan
Copy link

Hello,
First of all, thank you so much for this wonderful plugin. I had been looking for the capability to run my unit tests without exiting my favorite neovim editor for a long time.

Unfortunately, the development environment of my professional project requires executing the unit tests inside a Docker container instance. As a consequence, after the delegated execution, it is required to use a report in file format to retrieve the execution results. This solution is less elegant than your wrapping of the python script from Lua but I have found no other way.
Additionally, the default report format of pytest is not easy to parse in Lua, which is why I have used the python module pytest-json. The report is parsed to provide the result to the neotest root plugin.

To integrate all of this into your solution, I have added a few configuration properties to your plugin to be able to determine when a docker instance must be used and if so, which instance.

  • The use_docker parameter allows the plugin to build the command to launch locally so test execution happens in the docker instance. In the following example, this parameter is a static value but it could also be replaced by a function to allow conditional "dockerization".

  • The container parameter provides the name of the container to use for test execution. This parameter can also be a function to dynamically determine the name of the container.

For example, in the following configuration, I use the directory path as discriminator.

     require("neotest").setup({
         adapters = {
             require("neotest-python")({
                 dap = { justMyCode = false },
                 runner = "pytest",
                 use_docker = true,
                 container = function ()
                     local path = vim.loop.cwd()
                     if path ~= nil then
                         if string.find(path, '/dir1') then
                             return 'container-1'
                         elseif string.find(path, '/dir2') then
                             return 'container-2'
                         end
                     end
                     return ''
                 end
             }),
         },
     })

Feel free to say if something looks wrong to you. I am a complete beginner with Lua language and there are many things I might have missed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant