import unittest import os import sys # 获取当前文件所在目录的绝对路径 current_dir = os.path.dirname(os.path.abspath(__file__)) # 获取 developed_code 目录的绝对路径,并添加到 sys.path 中 developed_code_path = os.path.abspath(os.path.join(current_dir, '..')) sys.path.append(developed_code_path) # 打印 sys.path,确认路径是否正确 print("sys.path:", sys.path) # 尝试导入 to_allexcel 模块 try: import to_allexcel except ImportError as e: print(f"ImportError: {e}") class TestToAllExcel(unittest.TestCase): def test_count_danmu(self): danmu_list = ["测试弹幕"] * 5 result = to_allexcel.count_danmu(danmu_list) self.assertEqual(result["测试弹幕"], 5) if __name__ == '__main__': unittest.main()