Reputation: 3034
I have a Scheduler
class and a test written for __generate_potential_weeks
using unittest
class Scheduler:
def __init__(self, num_teams, num_weeks):
self.potential_weeks = self.__generate_potential_weeks(num_teams)
# Other stuff
def __generate_potential_weeks(self, num_teams):
# Does some things
import unittest
from main import Scheduler
class SchedulerTestCase(unittest.TestCase):
def test_generate_weeks(self):
sch = Scheduler(4, 14)
weeks = sch.__generate_potential_weeks(4)
When I try to test __generate_potential_weeks
, I get the following error
AttributeError: 'Scheduler' object has no attribute '_SchedulerTestCase__generate_potential_weeks'
__generate_potential_weeks
__generate_potential_weeks
? It has some complex logic I would like to test separately from Scheduler
Upvotes: 2
Views: 1182
Reputation: 3828
Double underscore has a special meaning within python. The name will be mangled to avoid a conflicting name in a subclass.
If that wasn't your intent, I'd encourage you to mark it with a single underscore. If it was, you can still access the function by using the mangled name. I think this will work for you: sch._Scheduler__generate_potential_weeks(4)
Upvotes: 3