Questions & Answers

simple unittest.FunctionTestCase() example

I have an existing python script that I'd like to test with python's unittest libary, specifically using unittest.FunctionTestCase()

Can anyone provide a simple 'actual' example of how someone might do this?

cheers for help

    def test_something(self):
        testCase1 = unittest.FunctionTestCase(existingFunctionToLoadWebPage)
        testCase2 = unittest.FunctionTestCase(existingFunctionToSubmitWebForm)
        testSuite = unittest.TestSuite((testCase1, testCase2))

        self.assertEqual(suite.countTestCases(), 2)
        # Validate the two existing functions above worked, even though then don't return anything:
2023-01-18 00:30:15
Why do you want to use FunctionTestCase? Is it just "I want to test a function, and FunctionTestCase sounds like a class designed to do that"? If so, you've misunderstood what FunctionTestCase is, and you should just write a normal test with unittest.TestCase.
2023-01-18 00:30:15
Have you read the documentation? And as pointed out by @user2357112, you don't want to use this if you're writing new tests.
Answers(0) :