当我使用pycharm运行我的代码时,我的代码正在执行,但是如果我尝试在cmd的帮助下做同样的事情,则会得到以下错误。 我不确定为什么会收到此错误,任何人都可以帮助我。 我正在使用的python版本是3.6.4
from unittest import TestLoader, TestSuite, TextTestRunner
from Test.TestSuite import HTMLTestRunner
from Test.Scripts.login_page import LoginPage
from Test.Scripts.register_page import Register
from Test.Scripts.category_page import CategoryPage
from Test.Scripts.Footer_page import Footer
from Test.Scripts.hamburger_page import HamburgerPage
from Test.Scripts.header_page import Header
from Test.Scripts.message_page import MessagePage
from Test.Scripts.new_topic_page import NewTopicPage
from Test.Scripts.profile_preference_page import ProfilePreferencePage
from Test.Scripts.search_page import SearchPage
from Test.Scripts.topic_page import TopicPage
from Test.Scripts.user_profile_links_page import UserProfilePage
if __name__ == "__main__":
loader = TestLoader()
suite = TestSuite((
loader.loadTestsFromTestCase(LoginPage),
loader.loadTestsFromTestCase(Register),
loader.loadTestsFromTestCase(CategoryPage),
loader.loadTestsFromTestCase(Footer),
loader.loadTestsFromTestCase(HamburgerPage),
loader.loadTestsFromTestCase(Header),
loader.loadTestsFromTestCase(MessagePage),
loader.loadTestsFromTestCase(NewTopicPage),
loader.loadTestsFromTestCase(ProfilePreferencePage),
loader.loadTestsFromTestCase(SearchPage),
loader.loadTestsFromTestCase(TopicPage),
loader.loadTestsFromTestCase(UserProfilePage)
))
#run test sequentially using simple TextTestRunner
runner = TextTestRunner(verbosity=1)
#runner.run(suite)
# open the report file
outfile = open("forum_page_test_results.html", "w")
# configure HTMLTestRunner options
runner = HTMLTestRunner.HTMLTestRunner(stream=outfile, title='Test report', description='Acceptance Tests')
# run the suite using HTMLTestRunner
runner.run(suite)
错误:文件“ TestRunner.py”,第2行,在 从Test.TestSuite导入HTMLTestRunner ModuleNotFoundError:没有名为“测试”的模块
答案 0 :(得分:0)
如果要开发的模块名为Test,则可能需要将包含该模块的目录添加到sys.path:
import sys
sys.path.append('/path/to/mod_directory')