0
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

5
  • 1
    Those are functions, not methods in the class. Commented Apr 29, 2020 at 12:38
  • 1
    I'm probably seeing the same problem @jonrsharpe has pointed out. Are you sure you have indented everything properly? Commented Apr 29, 2020 at 12:41
  • Like @JST99 and @jonrsharpe pointed out, your "tests" are not in the TestCaseDemo class. Just adjust your indentation. Commented Apr 29, 2020 at 12:51
  • JST99 and @jonrsharpe and Noah Broyles idenation is correct , I have also debug the code , its just not entering into the functions Commented Apr 30, 2020 at 4:21
  • It would help if you copied your code in so it displayed correctly. Commented Apr 30, 2020 at 4:54

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you it worked , I think test keyword is necessary

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.