ERROR: https://www (unittest.loader._FailedTest) while Unit Testing

ERROR: https://www (unittest.loader._FailedTest) while Unit Testing

目前正在尝试为特定函数编写单元测试。错误如下所示:

E
======================================================================
ERROR: https://www (unittest.loader._FailedTest)
----------------------------------------------------------------------
AttributeError: module '__main__' has no attribute 'https://www'

----------------------------------------------------------------------
Ran 1 test in 0.000s

FAILED (errors=1)

虽然函数本身没有在测试函数中被调用,但我正在尝试在测试中初始化一个 class Hasher。注释掉初始化行导致程序 运行。

class Test(unittest.TestCase): 

def test_YT(self): 
        self.H = Hasher()
        self.assertTrue(True)

class 的代码如下所示:

class Hasher:

    import hashlib 

    def __init__(self, hash_algo='md5'): 
        print('we getting here')
        # TODO: support for more hash algos
        self.hash_algo = hash_algo 


    def hash_file(self, filename):

        return hashlib.md5(open(filename, 'rb').read()).hexdigest()


    def compare_file_txt(self, filename, hash_txt_file):
        # Useful for when there is an MD5 txt in the folder

        hash1 = self.hash_file(filename)

        if hash1 == open(hash_txt_file).readline():
            return True

        return False


    def YT_create_hash(self, link, output_loc='test_hash.txt'):

        DL = Downloader()
        file_name = DL.YT_extract(link)
        hash_txt = self.hash_file(os.getcwd() + '/' + file_name)
        o_file = open(output_loc, 'w')
        o_file.write(hash_txt)
        o_file.close()

class 初始化中没有任何内容表明它正在使用 'https://www',因此不确定此错误的来源。

我的导入形式为:

from Hasher import *
from Downloader import *

我现在的文件结构是:

使用 from my module import * 几乎从来都不是一个好主意。这可能会导致与从其他模块导入的名称发生冲突,由于使用错误的函数或 class 而导致错误,以及不需要的副作用。
尽量只导入需要的对象。使用诸如 pylint 或 flake8 之类的工具,或者 IDE 中的内置提示,以便收到类似问题的通知。

在这个具体案例中,语句 from downloader import * 最有可能导致问题。