0

As an example I have the following python-program:

name = input('Type your name:')
print('Hello', name)

I would like to test this program with a unit test. The unit test should be able to enter the name (see line 1) and then test whether the program outputs the correct console output. Example: Enter Foo on the keyboard and test that the output is Hello Foo.

Background: I am a lecturer and I want to develop an interactive Python course for my students in PyCharm Edu. The individual exercises should be able to be checked with unit tests.

The answered question How to unittest local variable in Python does not solve my problem because I do not want to check the content of a local variable name in the test. I want the above program to be run by the unit test and a keyboard entry made with the input()-function. Then it should be checked whether the actual output of print('Hello', name) corresponds to the expected output.

Thank you in advance for your help.

Seb Krae
  • 191
  • 2
  • 10
  • `mock` the builtin `input` function: There's an answer [here](https://stackoverflow.com/questions/30039503/mock-user-input) – RufusVS Oct 08 '21 at 20:10

0 Answers0