How to test a function that is supposed to return NoneType? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: How to test a function that is supposed to return NoneType? (/thread-8382.html) |
How to test a function that is supposed to return NoneType? - w0mb4rt - Feb-17-2018 Hey all. I'm working on an assignment from an intro to Python course on Coursera and I'm trying to check all my functions. I have a function, shown below, that is supposed to return type NoneType. I am trying to test the function in the shell by creating a variable used in the function (player_info) and populating that variable with required information, and then seeing if my function changes the values stored in the variable. So far, I've had no luck. I referenced/looked up what a few other people have done for this function and I think that my code is good but I would ultimately like to know how I can test this function to be sure. def update_score(player_info, word): """ ([str, int] list, str) -> NoneType player_info is a list with the player's name and score. Update player_info by adding the point value word earns to the player's score. >>> update_score(['Jonathan', 4], 'ANT') >>> update_score(['Anthony', 4], 'JOBS') """ ## How to test? In shell I tried to assign str and int values to ## player_info to see if this function would change the value stored at ## player_info[1] but had no luck player_info = player_info[1] + word_score(word)The function calls another function (word_score) and that function works correctly as far as I can tell (have messed with it in the shell a couple different ways). The other variable, player_info, is in another file that is supposed to be the driver for this word-search game, and is a file that I was provided with in the MOOC course materials. RE: How to test a function that is supposed to return NoneType? - Gribouillis - Feb-17-2018 As such, the function is not correct. Line 16 should be player_info[1] = player_info[1] + word_score(word)Giving a new value to the local variable by a statement such as player_info = ... cannot change anything out of the function.
|