我有以下结构:
#in constants.py
MIN_VALUE = 0
MAX_VALUE = 100
#in calculator.py
import constants
class Calculator:
#Create initialiser (not used at the moment)
def __init__(self):
return
def get_sum(self, number1, number2):
return number1 + number2
def main():
calculator = Calculator()
print(calculator.get_sum(10, 10))
return
if __name__ == "__main__":
main()
print("")
exit(0)
#in tests.py
import unittest
import source_code.calculator as Calculator
class Test_Calculator(unittest.TestCase):
def setUp(self):
self.calculator = Calculator()
return
def test_calculator(self, number1, number2, errorMessage):
self.assertEqual(self.get_sum(number1, number2), expected_LBTT, errorMessage)
return
def main(self):
test_calculator(10, 10, "The calculated sum is wrong.")
return
if __name__ == "__main__":
unittest.main()
当我运行 calculator.py 时,它工作正常。 当我运行 tests.py 或 python -m unittest 时,出现以下错误:
================================================= ===================== **错误:测试(unittest.loader._FailedTest.tests) **-------------------------------------------- ---------------------- ImportError:无法导入测试模块:测试 追溯(最近一次通话): 文件“C:\Users\Home\AppData\Local\Programs\Python\Python311\Lib\unittest\loader.py”,第 407 行,在 _find_test_path 中 模块 = self._get_module_from_name(名称) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 文件“C:\Users\Home\AppData\Local\Programs\Python\Python311\Lib\unittest\loader.py”,第 350 行,在 _get_module_from_name 中 导入(名称) 文件“C:\Users\Home\Desktop\BJSS\project ests.py”,第 2 行,位于 将 source_code.calculator 导入为计算器 文件“C:\Users\Home\Desktop\BJSS\project\source_cod