[英]Unable to import class from another file in Python
I am trying to execute test suit by importing class from another file.我正在尝试通过从另一个文件导入 class 来执行测试套件。 I have file list as below - enter image description here我的文件列表如下 -在此处输入图像描述
I am using below -我在下面使用 -
import unittest
import HTMLTestRunner
from Enhancement.Exercise18_WriteExcel import TestEx18
from UnitTest.Exercise14_OrderFood import TestEx14
if __name__ == "__main__":
# import sys;sys.argv = ['', 'Test.testName']
unittest.main()
# get all tests from Login and SignUp class
tc1 = unittest.TestLoader().loadTestsFromTestCase(TestEx18)
tc2 = unittest.TestLoader().loadTestsFromTestCase(TestEx14)
# create a test suite combining tc1 and tc2
test_suite = unittest.TestSuite([tc1, tc2])
# run the suite
unittest.TextTestRunner(verbosity=1).run(test_suite)
#unittest.main(testRunner=HTMLTestRunner.HTMLTestRunner(output="demo/reports"))
But getting error - enter image description here但出现错误 -在此处输入图像描述
Kindly advise how can I resolve this issue.请告知我该如何解决这个问题。
Run the same command from /path/to/Selenium_Practice/ folder (and not /path/to/Selenium_Practice/Reporting/ folder)从 /path/to/Selenium_Practice/ 文件夹(而不是 /path/to/Selenium_Practice/Reporting/ 文件夹)运行相同的命令
Take a look at the answer found here ==> https://stackoverflow.com/a/28224295/16879293看看这里找到的答案 ==> https://stackoverflow.com/a/28224295/16879293
basically, you have 2 options, one would be to add your Enhancement to the PYTHONPATH, or you can simply add to your code:基本上,您有 2 个选项,一个是将您的增强功能添加到 PYTHONPATH,或者您可以简单地添加到您的代码中:
import sys
sys.append("..")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.