Home > Software design >  AttributeError: 'TestFiles' object has no attribute '_reports'
AttributeError: 'TestFiles' object has no attribute '_reports'

Time:11-22

I've two class one is in my test.py and another one is in my main.py file named as TestFiles and Files respectively. My Files class contain two method one is private _reports which is get called in another method named as get_file_data but when i run my pytest it gives this error

AttributeError: 'TestFiles' object has no attribute '_reports'

here is my TestFiles class

import Files

class TestFiles:
    def test_generate_output_files(self):
        Files.get_file_data(self)

this is my Files class

class Files:

    def _reports(self):
        # does some work
        pass

    def get_file_data(self):
        reports = self._reports()

CodePudding user response:

You're not creating a class - you're just calling the method. The self parameter will be the class object in that case, and you won't be able to access the private method on the class instance.

Instead you'll have to create the object and call the method on the object:

from Files import Files

class TestFiles:
    def test_generate_output_files(self):
        files_object = Files()
        files_object.get_file_data(self)
  • Related