alfredodeza / pytest.vim

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

fails on decorated methods #58

Closed davidszotten closed 6 years ago

davidszotten commented 6 years ago

Hi,

i have something like

class TestClass(object):
    @pytest.mark.django_db()
    def test_method(self):
        pass

when running Pytest method i get py.test ==> Running test for parametrized method test_method but it actually tries to run 'path/to/file.py'::TestClass

alfredodeza commented 6 years ago

The message is a bit misleading because it does call out to the class and then it filters by the method name. This is because py.test doesn't have support for parametrized test methods using the 'path/to/test.py::TestClass::test_method

Do you have unexpected execution of the parametrized test? Or does it execute and you are just worried about the message? Does :Pytest session look ok/expected ?

If this is about the messaging, I could improve it a bit I think, to signal that it is working with a parametrized method.

davidszotten commented 6 years ago

hey, thanks for the quick reply. and apologies if i wasn't clear: the point is that the test isn't parametrized at all, that's a regular pytest mark

alfredodeza commented 6 years ago

Ouch. Of course. We are being naive trying to detect this. I can get a fix so you can try it out in a bit, thanks for clarifying!

davidszotten commented 6 years ago

thank you!

alfredodeza commented 6 years ago

@davidszotten can you try a7abab2622021ca657f01fe4b5dce91dcafb39ee and tell me if that fixes this for you? I can then merge to master and hopefully close this ticket :)

davidszotten commented 6 years ago

yes, this seems to fix the issue

i don't quite follow why parametrized functions need special handling, from what i see they can be invoked just like non-parametrized ones

alfredodeza commented 6 years ago

This is because py.test can't use the notation of /path/test_file.py::TestClass:test_method when test_method is parametrized. I think this is because internally py.test is having signature for each parametrized execution.

That is why we use -k in this case, to specify up to the class, and then filter the test method with -k

Thanks for reporting this! Will push this to master

alfredodeza commented 6 years ago

This is the issue I reported a while back https://github.com/pytest-dev/pytest/issues/649

Seems to have been fixed recently, but I have to supported older versions of py.test so this has workaround has to stay for now

davidszotten commented 6 years ago

ah yes. looks like it was fixed in 2.9.1 (2016-03-17)

anyway. thanks for the fix for my current issue!