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

Python

How do i setup a unittest method that checks a method inside method?

Hello guys! I have been practicing my code testing skills with unittest, and one of the holes I found in my knowlage is how to test a method, that calles other method inside of it, that requires attributes. For example:

def calc_balance(usr_input)
    new_balance = total_income() - usr_input
    return new_balance

def total_income(value):
    return value

I want to test with unittest, for example: if usr_input = 100, and my total_income() method returns 50, the test will pass if new_balance will be equal to 50.

I know how to write a test for calc_balance() that assigns usr_inputs value (that's easy), but i don't know how to pass a value to total_income().

I'll be glad if someone could help me with that... i couldn't any usful info... I assume that maybe I need to use the seUp() method or something like that...

Someone?