Python - AttributeError: 'OnDemand' object has no attribute 'calc'
Question: Something is really happening and i couldnt resolve for a day almost

Examples are below: Trying a simple method calling from one class to another
class to figure out the problem as i have experienced the notorious problem
this morning as well... so have tried a simple method calling checks... Two
Class: HomePageAlone OnDemand

HomePageAlone - defined a test "def test_E_Access(self):" calls method in
OnDemand i got the below error.

Code as follows:

## HomePageAlone

    
    
    from sikuli import *
    from OnDemand import *
    import OnDemand
    
    class homePage(unittest.TestCase):
    
     def setUp(self):
      print("Test")   
    
    
     def test_E_Access(self):
      callMethod = OnDemand()
      callMethod.calc() # Line#15
    
    
    suite = unittest.TestSuite()
    suite.addTest(homePage('test_E_Access'))
    unittest.TextTestRunner(verbosity=2).run(suite)
    

## OnDemand

    
    
    from sikuli import *
    
    class OnDemand(object):
    
        def setUp(self):
            print("setup")
    
    
        def calc(self):
            print ("This is calling")
    

* * *

Log Message

======================================================================

## ERROR: test_E_Access (**main**.homePage)

Traceback (most recent call last): File
"C:\DOCUME~1\Senthil.S\LOCALS~1\Temp\sikuli-6018543662740221054.py", line 15,
in test_E_Access callMethod.calc(self) # Line#15 AttributeError: 'OnDemand'
object has no attribute 'calc'

* * *

Ran 1 test in 0.016s

FAILED (errors=1)

Another Try : i tried to use as the below snippet as your suggested - it
always throws AttributeError: 'OnDemandPopular' object has no attribute 'calc'

import OnDemandPopular ondemand = OnDemandPopular.OnDemandPopular()
ondemand.calc()

Please help

* * *


Answer: You should import **OnDemand** class from **OnDemand** module;

    
    
    from OnDemand import OnDemand
    

**HomePageAlone**

    
    
    import unittest
    from OnDemand import OnDemand
    
    class homePage(unittest.TestCase):
    
     def setUp(self):
      print("Test")   
    
     def test_E_Access(self):
      callMethod = OnDemand()
      callMethod.calc() # Line#15
    
    
    suite = unittest.TestSuite()
    suite.addTest(homePage('test_E_Access'))
    unittest.TextTestRunner(verbosity=2).run(suite)
    

**OnDemand**

    
    
    class OnDemand(object):
    
        def setUp(self):
            print("setup")
    
        def calc(self):
            print ("This is calling")
    

The Output is ;

    
    
    This is calling
    test_E_Access (HomePageAlone.homePage) ... ok
    
    Test
    This is calling
    ----------------------------------------------------------------------
    
    Ran 1 test in 0.000s
    
    OK
    Test
    This is calling
    

