alfredodeza / pytest.vim

Runs your UnitTests with py.test displaying red/green bars and errors
274 stars 40 forks source link

Can't specify name of alternative test directory #37

Closed dbedrenko closed 8 years ago

dbedrenko commented 8 years ago

I keep my tests in a directory called "test" rather than "tests", so when I run:

:Pytest project

It doesn't find any test files:

There are no tests defined for this project

I'm 1 year into development of this project so I'd really rather not rename the folder because it makes it a pain in the butt, e.g. if I want to use vim-fugitive to compare a file with an older commit the comparison would fail because the path to the file was different in that older commit.

It would be good if there was a way to specify where the project's test directory is.

For now, as a workaround, I will edit in pytest.vim the function s:ProjectPath(), on the line:

let projecttestdir = finddir('tests','.;')

PS: Huge thanks for such a useful plugin! I love it!

alfredodeza commented 8 years ago

I understand the use case but you would have a similar problem if the test files were using a prefix other than test_. In that case, I would say that changing your conftest.py file to use the python_files directive would be a good solution: http://pytest.org/latest/customize.html#confval-python_files

I was never a fan of using Pytest project, I meant the plugin to report on a succinct amount of tests, but then again, I do see your point.

Does the workaround sounds plausible?

dbedrenko commented 8 years ago

I understand the use case but you would have a similar problem if the test files were using a prefix other than test_

As far as I know, py.test requires that test filenames are prefixed with test_ but there is no requirement for the directory name; this is a requirement added by pytest-vim.

I was never a fan of using Pytest project , I meant the plugin to report on a succinct amount of tests, but then again, I do see your point.

It's a good feature of py.test that if I run the py.test command in the root dir of the project, it finds all the test files that are scattered in different directories; I thought the project argument to pytest-vim was meant to corresponded to that.

I would say that changing your conftest.py file to use the python_files directive would be a good solution

I think you meant "pytest.ini" instead of "conftest.py". I added a "pytest.ini" file to the root dir of my project:

[pytest]
python_files = test/test_*

py.test from the shell finds all the tests (and, if I change python_files to the wrong dir, it finds nothing). However, :Pytest project still says "There are no tests defined for this project"

Does the workaround sounds plausible?

Yeah, that's a decent workaround, but I can't get it to work.

alfredodeza commented 8 years ago

@Spaghetti-Cat thank you so much for reporting this and the discussion on IRC. I've added a fallback to check for a test directory as well since that is common (although not a good idea because it overrides a Python built-in).

Commit with fix is b428867198b638dbe5016ae7a99ec40a66d6dfc5

averagehat commented 5 years ago

This functionality (checking for test/ in addition to tests/) seems to have gotten lost somewhere along the way. Was that intentional?