No tests are being recognized within test files
It seems no tests within files are being discovered - when running file, or running nearest, or debugging nearest the result is "No tests found" from neotest. The test file, however, does show up in the summary window, but shows a "skipped" icon next to it when run.
I created a fresh venv with python 3.12, and installed just pytest 8.3.3, and implemented their getting started:
# filename: test_sample.py
def func(x):
return x + 1
def test_sample():
assert func(3) == 5
class TestClass:
def test_one(self):
x = "this"
assert "h" in x
def test_two(self):
x = "hello"
assert hasattr(x, "check")
Running pytest yields the following, expected, output:
Here's my output of nvim -v:
% nvim -v
NVIM v0.11.0-dev
Build type: RelWithDebInfo
LuaJIT 2.1.1703358377
Run "nvim -V1 -v" for more info
And I'm running LazyVim - here's the lazy-lock.json lines for neotest:
"neotest": { "branch": "master", "commit": "6d6ad113f56edc7c3f2a77a0836ea8c1b955ebea" },
"neotest-python": { "branch": "master", "commit": "72603dfdbaad5695160268cb10531a14cc37236e" },
and the rest of my configuration is here: https://github.com/a3ng7n/nvim
+1 getting this too after upgrading my nvim/neotest/neotest-pytest. Can't quite figure out which upgrade caused the regression
+1 getting this too after upgrading my nvim/neotest/neotest-pytest. Can't quite figure out which upgrade caused the regression
Yeah - I was suspecting this could be an issue in neotest proper as well, but just haven't spent enough time to figure out which.
I had this bug on nightly build. when moving to v0.10.0 the bug was gone
I had this bug on nightly build. when moving to
v0.10.0the bug was gone
is that v0.10.0 of neotest? or neotest-python?
if you're able to do any testing that might help track whether this is a bug in neotest or neotest-python
is that v0.10.0
sounds like he was talking about neovim version. BTW I'm also facing this issue on neovim 0.10.2
NOTE: After reinstalled properly it works, steps:
:LazyExtra- check
lang-pythonandneotest
+ "neotest": { "branch": "master", "commit": "6d3d22cdad49999ef774ebe1bc250a4994038964" },
+ "neotest-python": { "branch": "master", "commit": "a2861ab3c9a0bf75a56b11835c2bfc8270f5be7e" },
For me, this issue had to do with an outdated version of plenary.nvim (symptoms exactly as described). The latest release of plenary is from 2023. Plenary is used to detect filetypes in neotest, which returned nil on this version. Installing the latest git version of plenary.nvim fixed the issue for me.
Same issue on 0.10.2, all my Neotest adapters work fine, except Python for some reason.
But what is really funny, if I navigate into a Rust file with a test in it, and run the tests, then when I go back into the python file with tests and run them - neotest runs them 😅. If I make any test to fail, I can see python adapter actually reporting the test failure.
Otherwise I always see "No tests found" message.
I think I found the root cause of this issue. If you just add one of the following files into the root folder, even an empty one:
"pyproject.toml", "setup.cfg", "mypy.ini", "pytest.ini", "setup.py"
which I had none of, then tests should be discovered and you should be able to run them. At least it started working for me.
The issue was in Adapter.get_root function, neotest was looking for any of these files and if none of them are found, then it considers the folder to be not a neotest-enabled workspace.
Getting the same issue but I already have a pyproject.toml in my root dir.
I think I found the root cause of this issue. If you just add one of the following files into the root folder, even an empty one:
"pyproject.toml", "setup.cfg", "mypy.ini", "pytest.ini", "setup.py"which I had none of, then tests should be discovered and you should be able to run them. At least it started working for me.
The issue was in
Adapter.get_rootfunction,neotestwas looking for any of these files and if none of them are found, then it considers the folder to be not a neotest-enabled workspace.
I think it would be sensible to add .git to that list 😅
Hi! I have a similar issue: test_*.py files are recognized, but not their contents.
Versions of everything
pytest 8.3.5 NVIM v0.11.1
Part of lazy-lock.json that might be helpful (everything is latest I believe):
{
"FixCursorHold.nvim": { "branch": "master", "commit": "1900f89dc17c603eec29960f57c00bd9ae696495" },
"neotest": { "branch": "master", "commit": "862afb2a2219d9ca565f67416fb7003cc0f22c4f" },
"neotest-python": { "branch": "master", "commit": "a2861ab3c9a0bf75a56b11835c2bfc8270f5be7e" },
"nvim-nio": { "branch": "master", "commit": "21f5324bfac14e22ba26553caf69ec76ae8a7662" },
"nvim-treesitter": { "branch": "master", "commit": "066fd6505377e3fd4aa219e61ce94c2b8bdb0b79" },
"plenary.nvim": { "branch": "master", "commit": "857c5ac632080dba10aae49dba902ce3abf91b35" }
}
Neotest config
return {
"nvim-neotest/neotest",
dependencies = {
"nvim-neotest/nvim-nio",
"nvim-lua/plenary.nvim",
"antoinemadec/FixCursorHold.nvim",
"nvim-treesitter/nvim-treesitter",
"nvim-neotest/neotest-python",
},
config = function()
require("neotest").setup({
output = { open_on_run = true },
adapters = {
require("neotest-python")({
log_level = vim.log.levels.DEBUG,
runner = "pytest",
}),
}
})
end,
}
pytest is installed via pipx, running it from terminal works perfectly fine.
Sample project
.
├── main.py (empty)
├── pyproject.py (empty)
└── tests
└── test_dummy.py
Contents of tests/test_dummy.py:
def test_dummy() -> None:
assert 1 == 2
Behavior
Neotest summary shows the tests/test_dummy.py file, but without any contents:
Running all tests in the buffer turns question mark to skipped mark:
If anyone is still reading this issue, I think I've figured this one out.
Docs says:
Requires nvim-treesitter and the parser for python.
That was basically the case for me. It was a fresh nvim install and there was no treesitter for python.
Probably would be nice to add treesitter dependency to the docs example? I have it like this now:
return {
"nvim-neotest/neotest",
dependencies = {
"nvim-neotest/nvim-nio",
"nvim-lua/plenary.nvim",
"antoinemadec/FixCursorHold.nvim",
"nvim-neotest/neotest-python",
"nvim-treesitter/nvim-treesitter",
},
config = function()
require("nvim-treesitter.configs").setup {
ensure_installed = { "python" },
}
require("neotest").setup({
output = { open_on_run = true },
adapters = {
require("neotest-python")({
log_level = vim.log.levels.DEBUG,
runner = "pytest",
python = ".venv/bin/python",
}),
}
})
end,
}