alfredodeza / pytest.vim

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

:Pytest project always returns "no failed test from a previous run" unless current buffer is in tests dir #21

Closed ecerulm closed 9 years ago

ecerulm commented 9 years ago

In a project with the following structure

fakeproject/mypackage/__init__.py
fakeproject/mypackage/mymodule.py
fakeproject/mypackage/tests/test_mymodule.py

and running vim with fakeproject as current working directory.

If the current buffer is mymodule.py and I run :Pytest projectwd I get $HOME/tmp/fakeproject/mypackage/tests/ which it's ok. :Pytest project doesn't seem to execute any test.

On the other hand if the current buffer is test_mymodule.py and I run Pytest project then the test are execute and shows somo failing testcases (like it should).

I guess that :Pytest project should work from any location right?

alfredodeza commented 9 years ago

All that project will do is to pass that full path (as shown by Pytest projecttestwd to py.test

Can you on the CLI run directly that command with py.test and that path?

It would be ideal to see some output too

alfredodeza commented 9 years ago

Another thing you might want to try is to call :Pytest session as soon as this error pops up to see the actual output from py.test as Vim saw it from the terminal

ecerulm commented 9 years ago

Let's see Pytest projecttestwd gives /Users/ecerulm/tmp/testvimpytest/mypackage/tests when I'm in mypackage/mymodule.py. If I take that path and run that directly on the shell I get:

✗ py.test /Users/ecerulm/tmp/testvimpytest/mypackage/tests                                        19:24:21
============================= test session starts ==============================
platform darwin -- Python 2.7.8 -- py-1.4.25 -- pytest-2.6.3
collected 1 items

mypackage/tests/test_mymodule.py F

=================================== FAILURES ===================================
____________________________ TestMyModule.test_name ____________________________

self = <test_mymodule.TestMyModule testMethod=test_name>

    def test_name(self):
>       self.assertTrue(False)
E       AssertionError: False is not true

mypackage/tests/test_mymodule.py:14: AssertionError
=========================== 1 failed in 0.02 seconds ===========================

If I do :Pytest project I get No failed tests from a previous run but if I do :Pytest session after I can see failed results (I think is exactly the same result I get from the CLI)

============================= test session starts ==============================
platform darwin -- Python 2.7.8 -- py-1.4.25 -- pytest-2.6.3
collected 1 items

mypackage/tests/test_mymodule.py F

=================================== FAILURES ===================================
____________________________ TestMyModule.test_name ____________________________
mypackage/tests/test_mymodule.py:14: in test_name
    self.assertTrue(False) 
E   AssertionError: False is not true
=========================== 1 failed in 0.02 seconds ===========================

So it seems to be invoking py.test properly, but the reporting No failed test from a previous run is incorrect or at least misleading. Specially when running the same Pytest project from the test_mymodule.py buffer has a different behaviour (it opens a new window with the failing testcases)

alfredodeza commented 9 years ago

Could you make sure you are using the latest version from the master branch? That will help me debug this

ecerulm commented 9 years ago

I was already on 27dfa1e . I just installed pytest.vim last week. it's my first experience with it.

alfredodeza commented 9 years ago

@ecerulm mind trying this again? This should be fixed now!

ecerulm commented 9 years ago

Perfect, now it works like I expected! Thanks!