Nosetests with input taking functions

Hi everyone,
I have just arrived at exercise 52 and in order to wrap things up I first wanted to write a super simple engine myself (already quite some time ago since I worked on these problems and I wanted to make sure I understand the basics).

What I cannot figure out is how I would write a Nosetest function to test the ‘input_check’ function in my engine that awaits a user input in the middle of it?
I saw how you load a function and pass on a variable at the beginning but is it possible to test a function like mine using Nosetests?

Let me know if you have questions in case I was not clear enough.
Many many thanks for any help in advance.

My Engine:

class Engine(object):

def __init__(self):
    self.current_scene = central_corridor
    self.final_scene = generic_death
    self.action =""

def play(self):

    while self.current_scene != self.final_scene:
        next_scene = self.current_scene.paths.get(self.action)
        self.current_scene = next_scene

def input_check(self):
    path_list_dict = []
    path_list_keys = []

    for item in self.current_scene.paths:
    self.action = input("> ")

    if self.action in path_list_dict:
        return self.action

Have you checked out mocking input with the mock library and side_effects?

1 Like

Hi @gpkesley
Thanks so much for your response! very much appreciated!

I did some research and actually found something that solves the problem.
You are right ‘mock’ is the keyword in that regards.
A different article in this forum help a lot as well: Testing input() and print()

Many thanks again for your help!