0

使用 python 控制台计算器应用程序。

我的main_tests.py文件包含一个且唯一的测试用例,如下所示:

class CalculatorTest(TestCase):

    def test1(self):
        with patch('sys.stdout', new=StringIO()) as fake_out:
            source.square_root_function(-10)
            self.assertEqual(fake_out.getvalue(), "The number cannot be negative.")

下面是对应square_root_function()的待测试:

def square_root_function(m):
    try:
        print("Answer: " + str(math.sqrt(m)))
    except ValueError:
        print("The number cannot be negative.")

使用pybuilder 它执行构建时说:

 Executing unit tests from Python modules in /home/demonwolf/PycharmProjects/miniproject-scientific_calculator_devops/src/unittest/python
[INFO]  Executed 1 unit tests
[ERROR] Test has error: unittest.loader._FailedTest.main_tests
------------------------------------------------------------
BUILD FAILED - There were 1 error(s) and 0 failure(s) in unit tests (site-packages/pybuilder/plugins/python/unittest_plugin.py:114)
------------------------------------------------------------
4

0 回答 0