Giter VIP home page Giter VIP logo

Comments (13)

rcarriga avatar rcarriga commented on August 18, 2024
    is_test_file = function(file_path)
   end

This is going to always say a file path is not a test file because of implicitly returning nil. Remove it from the config

from neotest.

armanschwarz avatar armanschwarz commented on August 18, 2024

I tried using this instead:

require("neotest").setup({
  adapters = {
    require("neotest-python")({
        -- Extra arguments for nvim-dap configuration
        dap = { justMyCode = false },
        -- Command line arguments for runner
        -- Can also be a function to return dynamic values
        args = {"--log-level", "DEBUG"},
        -- Runner to use. Will use pytest if available by default.
        -- Can be a function to return dynamic value.
        runner = "unittest"
    })
  }
})

But I get the same result.

from neotest.

rcarriga avatar rcarriga commented on August 18, 2024

my_test_case is not a valid test name, please be sure the tests are actually runnable using the unittest cli.

from neotest.

armanschwarz avatar armanschwarz commented on August 18, 2024

That was just a mve. I changed it to test_my_test_case and it's the same issue.

arman@docker-desktop: ~ $ python -m unittest mytest.py
.
----------------------------------------------------------------------
Ran 1 test in 0.000s

OK

from neotest.

rcarriga avatar rcarriga commented on August 18, 2024

OK can you update your plugins to the latest, retry and provide the log in vim.fn.stdpath("log") .. "neotest.log"?

from neotest.

armanschwarz avatar armanschwarz commented on August 18, 2024
INFO | 2022-07-02T23:33:12Z+1000 | ....config/nvim/plugged/neotest/lua/neotest/client/init.lua:522 | Initialising client
INFO | 2022-07-02T23:33:12Z+1000 | ....config/nvim/plugged/neotest/lua/neotest/client/init.lua:589 | Initialisation finished in 0 seconds

from neotest.

rcarriga avatar rcarriga commented on August 18, 2024

Just saw your test file name is mytest.py, this is not an expected test file name. If you run python -m unittest it won't see your file. You should rename it to test_mytest.py. You can force it to be detected by neotest by changing the is_test_file option but it won't work when running directories

from neotest.

armanschwarz avatar armanschwarz commented on August 18, 2024

Changed the name to test_mytest.py. No change.

arman@docker-desktop: ~/stuff $ python -m unittest
.
----------------------------------------------------------------------
Ran 1 test in 0.000s

OK

from neotest.

rcarriga avatar rcarriga commented on August 18, 2024

If you use this init.lua does it work? nvim --clean -u min.lua test_mytest.py

-- ignore default config and plugins
vim.opt.runtimepath:remove(vim.fn.expand("~/.config/nvim"))
vim.opt.packpath:remove(vim.fn.expand("~/.local/share/nvim/site"))
vim.opt.termguicolors = true

-- append test directory
local test_dir = "/tmp/nvim-config"
vim.opt.runtimepath:append(vim.fn.expand(test_dir))
vim.opt.packpath:append(vim.fn.expand(test_dir))

-- install packer
local install_path = test_dir .. "/pack/packer/start/packer.nvim"
local install_plugins = false

if vim.fn.empty(vim.fn.glob(install_path)) > 0 then
  vim.cmd("!git clone https://github.com/wbthomason/packer.nvim " .. install_path)
  vim.cmd("packadd packer.nvim")
  install_plugins = true
end

local packer = require("packer")

packer.init({
  package_root = test_dir .. "/pack",
  compile_path = test_dir .. "/plugin/packer_compiled.lua",
})

packer.startup(function(use)
  -- Packer can manage itself
  use("wbthomason/packer.nvim")

  use("vim-test/vim-test")
  use({
    "nvim-neotest/neotest",
    requires = {
      "nvim-lua/plenary.nvim",
      "nvim-treesitter/nvim-treesitter",
      "antoinemadec/FixCursorHold.nvim",
      "nvim-neotest/neotest-python",
    },
    config = function()
      require("neotest").setup({
        adapters = {
          require("neotest-python")({
            dap = { justMyCode = false },
            args = { "--log-level", "DEBUG" },
            runner = "unittest",
          }),
        },
      })
    end,
  })

  if install_plugins then
    packer.sync()
  end
end)

vim.cmd([[
command! NeotestSummary lua require("neotest").summary.toggle()
command! NeotestFile lua require("neotest").run.run(vim.fn.expand("%"))
command! Neotest lua require("neotest").run.run(vim.fn.getcwd())
command! NeotestNearest lua require("neotest").run.run()
command! NeotestDebug lua require("neotest").run.run({ strategy = "dap" })
command! NeotestAttach lua require("neotest").run.attach()
]])

from neotest.

rcarriga avatar rcarriga commented on August 18, 2024

You'll also have to run TSInstall python and restart after installing plugins

from neotest.

armanschwarz avatar armanschwarz commented on August 18, 2024

It seems to work with that init.lua file you provided:

  import unittest


  class MyTest(unittest.TestCase):
✔     def test_my_test_case(self) -> None:
          self.assertTrue(True)

I'm confused about what the difference is though, as I thought that the init.vim file I provided in the OP is basically the same thing as what you gave me, but somehow it seems to work. Any ideas?

from neotest.

armanschwarz avatar armanschwarz commented on August 18, 2024

Ah so I tried again with my init.vim and it actually worked fine after running TSInstall python, so apparently that was the missing step.

from neotest.

armanschwarz avatar armanschwarz commented on August 18, 2024
diff --git a/README.md b/README.md
index ba87818..39fd4a6 100644
--- a/README.md
+++ b/README.md
@@ -27,12 +27,12 @@ See `:h neotest` for details on neotest is designed and how to interact with it

 ## Installation

-Neotest uses [plenary.nvim](https://github.com/nvim-lua/plenary.nvim/).
-
-Most adapters will also require [nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter).
-
 Neotest uses the `CursorHold` event which has issues in NeoVim: [see here](https://github.com/neovim/neovim/issues/12587) \
-It's recommended to use https://github.com/antoinemadec/FixCursorHold.nvim.
+It's recommended to use https://github.com/antoinemadec/FixCursorHold.nvim. Neotest uses \
+[plenary.nvim](https://github.com/nvim-lua/plenary.nvim/). Most adapters will also require \
+[nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter) (and for the correct \
+[language parser](https://github.com/nvim-treesitter/nvim-treesitter#language-parsers) to be installed, e.g. by running\
+`:TSInstall all`).

 Install with your favourite package manager alongside nvim-dap

from neotest.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.