Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Can't install neotest for Python #480

Closed
benabub opened this issue Dec 3, 2024 · 1 comment
Closed

[Question] Can't install neotest for Python #480

benabub opened this issue Dec 3, 2024 · 1 comment

Comments

@benabub
Copy link

benabub commented Dec 3, 2024

Hello! Pls, some help for newbie!
I have a plugins dir for Lazy in my nvim set. The instruction I've used for all the plugins I've installed:

  1. creating plugin-name.lua in this dir with return{} in it
  2. paste installation code for Lazy from GitHub's README between brackets

In this case its seems to be more complicated: I had no deal with adapters before.
So, for my neotest.lua file, all I got from my mind palace (and README chunks) is following:

return {
  {
    'nvim-neotest/neotest',
    dependencies = {
      'nvim-neotest/nvim-nio',
      'nvim-lua/plenary.nvim',
      'antoinemadec/FixCursorHold.nvim',
      'nvim-treesitter/nvim-treesitter',
    },
    config = function()
      require('neotest').setup {
        adapters = {
          require 'neotest-python' {
            dap = { justMyCode = false },
          },
          require 'neotest-plenary',
          require 'neotest-vim-test' {
            ignore_file_types = { 'python', 'vim', 'lua' },
          },
        },
      }
    end,
  },
}

The result of such beautiful code is the full screen of red errors:

Failed to run `config` for neotest                                                                               
                                                                                                                 
/home/usr/.config/nvim/lua/plugins/custom/neotest.lua:13: module 'neotest-python' not found:                  
^Ino field package.preload['neotest-python']                                                                     
^Icache_loader: module 'neotest-python' not found                                                                
^Icache_loader_lib: module 'neotest-python' not found                                                            
^Ino file './neotest-python.lua'                                                                                 
^Ino file '/usr/share/luajit-2.1.0-beta3/neotest-python.lua'                                                     
^Ino file '/usr/local/share/lua/5.1/neotest-python.lua'                                                          
^Ino file '/usr/local/share/lua/5.1/neotest-python/init.lua'                                                     
^Ino file '/usr/share/lua/5.1/neotest-python.lua'                                                                
^Ino file '/usr/share/lua/5.1/neotest-python/init.lua'                                                           
^Ino file './neotest-python.so'                                                                                  
^Ino file '/usr/local/lib/lua/5.1/neotest-python.so'                                                             
^Ino file '/usr/lib/x86_64-linux-gnu/lua/5.1/neotest-python.so'                                                  
^Ino file '/usr/local/lib/lua/5.1/loadall.so'                                                                    
                                                                                                                 
# stacktrace:                                                                                                    
  - .config/nvim/lua/plugins/custom/neotest.lua:13 _in_ **config**                                              
  - .config/nvim/lua/core/lazy.lua:22                                                                            
  - .config/nvim/init.lua:3        
@benabub
Copy link
Author

benabub commented Dec 3, 2024

Solved by myself.
Working neotest.lua file:

return {
  'nvim-neotest/neotest',
  event = 'VeryLazy',
  config = function()
    require('neotest').setup {
      adapters = {
        require 'neotest-python' {
          env = { CI = true },
          cwd = function(path)
            return vim.fn.getcwd()
          end,
        },
      },
    }
  end,
  dependencies = {
    'nvim-lua/plenary.nvim',
    'nvim-treesitter/nvim-treesitter',
    'antoinemadec/FixCursorHold.nvim',
    'neotest-python',
  },
}

Changes to keymappings.lua file:

-- Neotest
vim.keymap.set('n', '<leader>tn', function()
  require('neotest').run.run()
end, { desc = 'Run nearest test in the file' })

vim.keymap.set('n', '<leader>tt', function()
  require('neotest').run.run(vim.fn.expand '%')
end, { desc = 'Run all the tests in the file' })

vim.keymap.set('n', '<leader>to', function()
  require('neotest').output.open { enter = true }
end, { desc = 'output.open' })

vim.keymap.set('n', '<leader>ts', function()
  require('neotest').summary.toggle()
end, { desc = 'summary_toggle' })

vim.keymap.set('n', '<leader>tw', function()
  require('neotest').watch.watch()
end, { desc = 'watch current test for changes' })

@benabub benabub closed this as completed Dec 3, 2024
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

No branches or pull requests

1 participant