'模块'对象没有属性

时间:2016-08-25 22:35:06

标签: python-2.7

我是python的新手,我正在玩unittest和nosetests。

def revenue(r):
    return r * (1)

def profit (p):
    return p * (1.0-.05)

import unittest 
class MyTest(unittest.TestCase):
def test_revenue(self):
    self.assertEqual( revenue(0), 0 )
    self.assertEqual( revenue(10), 10)
    self.assertEqual( revenue(100), 100)

def test_profit(self):
    self.assertEqual( profit(0), 0)
    self.assertEqual( profit(10), 9.5)
    self.assertEqual( profit(100), 95)



unittest.main()

单元测试似乎工作正常,但是当我尝试在其上运行测试时,它总是失败并出现相同的错误" AttributeError:' module'对象没有属性' test_employee'"

我觉得可能有一个简单的答案,但是我很难过,任何帮助都会受到赞赏

" test_employee"是.py文件的名称。

我得到的跟踪错误是

"错误:失败:属性错误('模块'对象没有属性' test_employee')

Traceback (most recent call last):
File "c:\python27\lib\site-packages\nose\loader.py", line 418,in        loadTestsFromName
addr.filename, addr.module)
File "c:\python27\lib\site-packages\nose\importer.py", line 47, in     importFromPath
return self.importFromDir(dir_path, fqname)
File "c:\python27\lib\site-packages\nose\importer.py", line 94, in importFromDir
mod = load_module(part_fqname, fh, filename, desc)
File "C:\Users\----\Localclone\test_employee.py", line 22, in <module>
unittest.main()
File "c:\python27\lib\unittest\main.py", line 94, in __init__
self.parseArgs(argv)
File "c:\python27\lib\unittest\main.py", line 149, in parseArgs
self.createTests()
File "c:\python27\lib\unittest\main.py", line 158, in createTests
self.module)
File "c:\python27\lib\unittest\loader.py", line 130, in loadTestsFromNames
suites = [self.loadTestsFromName(name, module) for name in names]
File "c:\python27\lib\unittest\loader.py", line 100, in loadTestsFromName
parent, obj = obj, getattr(obj, part)
AttributeError: 'module' object has no attribute 'test_employee'"

0 个答案:

没有答案