Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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()

>Solution :

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading