nvim-neotest / neotest-python

MIT License
137 stars 40 forks source link

No tests found: How to configure/diagnose test suite detection? #3

Closed wookayin closed 2 years ago

wookayin commented 2 years ago

An example test suite is based on pytest with the following structure:

But this test case is not detected: Neotest says "No tests found". However, If the filename is like test_data.py (instead of data_test.py), the test cases can be found.

My guess is that the plugin is assuming some specific filename pattern. But this seems not documented somewhere. Actually, xxx_test.py is a very valid file name for test suites and my test runner (pytest) can collect them without any problems.

How can I customize, or debug how test cases are deteced and collected?

wookayin commented 2 years ago

In addition, test cases may have names like testCamelCase rather than test_snake_case. The hard-coded syntax can be also relaxed: https://github.com/rcarriga/neotest-python/blob/master/lua/neotest-python/base.lua#L49

rcarriga commented 2 years ago

I've updated the file detection to allow tests ending in _test.py now as well.

In addition, test cases may have names like testCamelCase rather than test_snake_case. The hard-coded syntax can be also relaxed: https://github.com/rcarriga/neotest-python/blob/master/lua/neotest-python/base.lua#L49

This is old unused code, the existing code already allows for any function/method starting with test

wookayin commented 2 years ago

Thanks, the latest commit works well.

You might want to make it even more configurable as other plugins (see https://github.com/vim-test/vim-test/blob/master/autoload/test/python/pytest.vim#L2), through some lua code for setting up adapters, but I think the current one will cover most of the practical cases.

feslima commented 2 years ago

Hi! Awesome plugin!

I know this is marked as resolved and all, but I would like to know how to proceed when dealing with non-conventional test file naming.

For example, I place all my test files under a tests directory without test_ or _test prefix/suffix, using vim-ultest + vim-test, set the vim-test parameter as vim.g["test#python#pytest#file_pattern"] = [[\v.+\.py$]] somewhere in my config files and proceed as normal. (Same parameter that is being set in the link that @wookayin mentioned above).

Is it possible to have something similar using this plugin? Or any guidelines if I were to open a PR with this feature?

rcarriga commented 2 years ago

I've added is_test_file as an option to provide to the adapter. You can provide whatever logic you like now :smile: