Home > front end >  Unable to import class from another file in Python
Unable to import class from another file in Python

Time:09-21

I am trying to execute test suit by importing class from another file. 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.

CodePudding user response:

Take a look at the answer found here ==> 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 :

import sys
sys.append("..")

CodePudding user response:

Run the same command from /path/to/Selenium_Practice/ folder (and not /path/to/Selenium_Practice/Reporting/ folder)

  • Related