Why does python only run a single test_method in my TestCase?

I have a set of unit tests that look basically like this:

import unittest

class MyTestCase(unittest.TestCase):

    def test_one(self):
        self.assertEqual(1,1)

    def test_two(self):
        self.assertEqual(2,2)


if __name__ == '__main__':
    unittest.main()

When I run the tests, I would expect to see results from both test_methods (test_one and test_two), but I only get results for one:

$ python -m unittest -v tests.test_dummy
test_one (tests.test_dummy.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.000s

OK

What's going on here?

Answers


Oh, this is mortifying.

It was an indentation problem. The test file had a combination of tabs and spaces, so the second test wasn't being identified.

I copied the invisible glitch from my real code, to the simplified MyTestCase class I used to replicate the error. But stackoverflow stripped out the tabs, so no one else was able to replicate.

Here's the bug that was killing my code. Tabs are shown with hyphens: ----

import unittest

class MyTestCase(unittest.TestCase):

    def test_one(self):
        self.assertEqual(1,1)

----def test_two(self):
--------self.assertEqual(2,2)


if __name__ == '__main__':
    unittest.main()

Need Your Help

Issue in viewscope

jsf-2 primefaces

I'm using primefaces 3.1

How do I get rowcount of a cte in a separate dataset?

performance sql-server-2008 common-table-expression

I have identified a way to get fast paged results from the database using CTEs and the Row_Number function, as follows...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.