Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


I am having some issues with Unit testing:


def userchoice1():
    grabs and validates user choice

    Initialize menu object to display menu items variable menu1 prompts for
    and stores user input while loop runs until user provides a valid input
    based upon input the method calls: either self.user_entry_data method
    or will call an instance of menu.submenu() which is a method of
    Menu class

    # grab and store user input
    menu = Menu()
    while True:
        menu1 = input(
                        'please choose '
                        'option a), or '
                        'option b) '
        # tests for a valid resonse
        # if user provides valid response loop will break
        if menu1.lower() not in ('a', 'b'):
            print("Not an appropriate choice.")
    # based upon user input call method
    if menu1 == 'a':
        main = Main()
    elif menu1 == 'b':
        sub = Main()
 def test_user_choice(self, Mockinput):
        #so I creating a sideeffect to see if 'a'
        Mockinput.side_effect =['a']
        expected_output = main.userchoice1()
        #var that will be passed to return value
        returnvalue = ('ted',
                       utilities.datetime(1999, 12, 23, 0, 0),
        #trying an objectpatch to mock function with my return values
        with patch.object(main, 'main.data_collection', return_value=returnvalue, side_effect=None) as mock:
            expected_output = main.userchoice1()

So I am trying to come up with a Testing strategy for this function, currently I am patching builtins.Input using the unittest.mock' library. here are some behaviors of the function takes a input ifinput= 'a' So Ideally I would want if a: main.main.user_entry_data assert called once else Menu.submenu called once