diff --git a/tested/languages/python/generators.py b/tested/languages/python/generators.py index 82965aaa..450c7e45 100644 --- a/tested/languages/python/generators.py +++ b/tested/languages/python/generators.py @@ -141,6 +141,7 @@ def convert_execution_unit(pu: PreparedExecutionUnit) -> str: import sys import importlib from decimal import Decimal +import builtins """ # Import the language specific functions we will need. @@ -152,6 +153,14 @@ def convert_execution_unit(pu: PreparedExecutionUnit) -> str: value_file = open("{pu.value_file}", "w") exception_file = open("{pu.exception_file}", "w") + +# Overwrite the input function +__old_input = builtins.input +def _our_input(_prompt=None): + return __old_input() +builtins.input = _our_input + + def write_separator(): value_file.write("--{pu.testcase_separator_secret}-- SEP") exception_file.write("--{pu.testcase_separator_secret}-- SEP") diff --git a/tests/exercises/echo/solution/input-prompt.py b/tests/exercises/echo/solution/input-prompt.py new file mode 100644 index 00000000..d2bb3c6f --- /dev/null +++ b/tests/exercises/echo/solution/input-prompt.py @@ -0,0 +1,2 @@ +i = input("This is a prompt: ") +print(i) diff --git a/tests/test_functionality.py b/tests/test_functionality.py index 517e1de8..284bc045 100644 --- a/tests/test_functionality.py +++ b/tests/test_functionality.py @@ -986,3 +986,18 @@ def test_language_literals_work(language: str, tmp_path: Path, pytestconfig): result = execute_config(conf) updates = assert_valid_output(result, pytestconfig) assert updates.find_status_enum() == ["correct"] + + +def test_python_input_prompt_is_ignored(tmp_path: Path, pytestconfig): + conf = configuration( + pytestconfig, + "echo", + "python", + tmp_path, + "one.tson", + "input-prompt", + ) + + result = execute_config(conf) + updates = assert_valid_output(result, pytestconfig) + assert updates.find_status_enum() == ["correct"]