alfredodeza / pytest.vim

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

Doesn't work when vim's current directory isn't the same as the test's file directory. #11

Closed donvargax closed 12 years ago

donvargax commented 12 years ago

When you run Pytest on a file in a different directory than the current working directory, pytest shows the following message:

"No failed tests from a previous run"

If I change the current directory to the one where the test file is, everything works correctly.

alfredodeza commented 12 years ago

Interesting problem.

The way py.test is called is by detecting the absolute path to the current file being edited and then passing that value along with your choice of test (class, method, function or file). It would look something like:

py.test /path/to/test_file.py::TestClass::TestMethod

So it really doesn't matter were you are executing this from. I can't really replicate this given the above description of how the plugin works, but I am definitely interested in solving the problem.

Could you describe a bit more the workflow you are using to get to that message? Are you looking at :Pytest session when the run is complete? It would be useful to know that output as that collects the exact py.test output as it happened on the shell.

Do you see a green bar with that message? or just red-colored letters?

Is this behavior specific to a project? Have you tried reproducing the problem from scratch in a clean virtualenv?

donvargax commented 12 years ago

Hi!

I'm now realizing that this only happens when a test fails, if all tests pass then the green bar with the ok message appears.

Here's what I'm doing: I open gvim in my project directory, then I open the test file which is in ./proj/test/test.py, after that I just execute :Pytest file and it shows the message I told you about before in red-colored letters. If I :lcd proj/test and then execute :Pytest file again it detects tests failures.

Checking :Pytest session after it doesn't work it looks like everything worked ok. It shows the output of py.test as if it was executed in the command line with the tests failures information.

I haven't tried reproducing this problem but I'll give it a try later. I'll disable all other vim plugins and check with a new project and a new virtualenv.

alfredodeza commented 12 years ago

I am closing this ticket as I have not been able to replicate your problem. If you find a way to do so, please feel free to re-open this issue so I can provide a fix.

gabehollombe commented 9 years ago

I just had the same problem as @kashano above. In my case, though, it happened because I had colorized output enabled in my pytest.ini:

[pytest]
addopts = --color=yes

Removing this from the config fixed the issue for me.

alfredodeza commented 9 years ago

@gabehollombe would you mind pulling from master and check if 992e288d9f24c1eb81395a70b718c9e3992e4a7b fixes that problem for you? (regardless of color in py.test)

ev-agelos commented 8 years ago

My structure is: My project/ ------app1/ ---------tests/ ------------unit/ ---------------test_something.py ------------functional/ ---------------test_something_else.py ------app2/....

I am on directory my_project/app1 and open the file tests/unit/test_something.py I run :Pytest function and shows green bar with all tests passed and then i type :Pytest session and shows the error!

When i move directory to my_project/app1/tests and open the unit/test_something.py works as expected.

alfredodeza commented 8 years ago

@ev-agelos please open a separate issue for this describing what errors you see and if possible a way to replicate. This particular ticket has been closed for a while and does not look related to what you are describing. Thanks!