alfredodeza / pytest.vim

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

Is there any support for unittest #57

Closed kraxli closed 6 years ago

kraxli commented 6 years ago

Hi thanks for your plugin!

I am just wondering if there is support for unittest? For example:

import unittest
class TestClass(unittest.TestCase):

    def failing_test(self):
        self.assertEqual(1, 2)
alfredodeza commented 6 years ago

@kraxli this totally works. I think your failing_test doesn't work because py.test will not pick up failing_test as a valid test method. It would need to be test_failing. That is: it needs to be prefixed by test_. Can you try that out and see if it works for you? (it does for me):

$ cat test_case.py
import unittest
class TestClass(unittest.TestCase):

    def test_failing_test(self):
        self.assertEqual(1, 2)

From vim:

============================= test session starts ==============================
platform darwin -- Python 2.7.8, pytest-3.2.3, py-1.4.34, pluggy-0.4.0
rootdir: /Users/alfredo/tmp, inifile:
plugins: xdist-1.15.0, celery-4.0.1
collected 1 item

test_case.py F

=================================== FAILURES ===================================
_________________________ TestClass.test_failing_test __________________________
test_case.py:5: in test_failing_test
    self.assertEqual(1, 2)
E   AssertionError: 1 != 2
=========================== 1 failed in 0.05 seconds ===========================
alfredodeza commented 6 years ago

I will close this since it works for me. Feel free to re-open if you find an issue.