我是Python的新手,我目前正在尝试使用名为test_account的模块编写一个简单的单元测试,但是立即无法识别该模块:
ImportError: No module named test_account
我跑步时:
python -m unittest test_account
这是单元测试:
import unittest
from python_challenge import MarketSegment
class TestUniqueSegmentAccounts(unittest.TestCase):
def test_account(self):
self.isInstance(add_account(acc1, MarketSegment('Consumer Goods', [acc1, acc2])))
这是该类的样子:
class MarketSegment(object):
def __init__(self, name, accounts=None):
self.name = name
self._accounts = []
if accounts:
self._accounts.extend(accounts)
def __str__(self):
return "{self.name}".format(self=self)
def add_account(self, account):
if account in self._accounts:
raise ValueError ('Accounts cannot be assigned to the same Market Segment more than once.')
else:
self._accounts.append(account)
account.set_market_segments(self)
return self._accounts
**更新:我已经尝试添加__初始化__ .py文件并安装pytest,但是都没有用。我发现在... / unittest / __ main __.py中,模块= None
<module> main(module=None)