Reputation: 33
import unittest
class TestCaseDemo(unittest.TestCase):
def setUp(self):
print('setUP')
def any_test(self):
print('test')
def tearDown(self):
print('tearDown')
unittest.main()
Output:
Ran 0 tests in 0.000s
OK
Process finished with exit code 0
Upvotes: 0
Views: 514
Reputation: 8674
The issue (aside from indentation) is that your test function doesn't start with test
. Using the unittest (docs) module requires that naming.
import unittest
class TestStringMethods(unittest.TestCase):
def test_upper(self):
self.assertEqual('foo'.upper(), 'FOO')
def this_is_not_a_test(self):
print("doesn't start with 'test'")
From the "Basic Example" documentation:
A testcase is created by subclassing unittest.TestCase. The three individual tests are defined with methods whose names start with the letters
test
. This naming convention informs the test runner about which methods represent tests.
Upvotes: 3