FAQ¶
Can I change how the user answer is displayed?¶
See also
Yes, especially for list type prompts with multiple selection, printing selection
as a list is not ideal in a lot of scenarios. Use transformer parameter to customise it.
How can I do unittest when using InquirerPy?¶
Tip
Since InquirerPy module itself is tested, there’s no need to mock any futher/deeper than the API entrypoint (prompt and inquirer).
For Classic Syntax (PyInquirer) user, it would be just a direct mock on the prompt function.
from InquirerPy import prompt
def get_name():
return prompt({"type": "input", "message": "Name:"})
import unittest
from unittest.mock import patch
from Module.somefunction import get_name
class TestPrompt(unittest.TestCase):
@patch("Module.somefunction.prompt")
def test_get_name(self, mocked_prompt):
mocked_prompt.return_value = "hello"
result = get_name()
self.assertEqual(result, "hello")
For Alternate Syntax user, you’d have to mock 1 level deeper to the prompt class level.
from InquirerPy import inquirer
def get_name():
return inquirer.text(message="Name:").execute()
import unittest
from unittest.mock import patch
from Module.somefunction import get_name
class TestPrompt(unittest.TestCase):
@patch("Module.somefunction.inquirer.text")
def test_get_name(self, mocked_prompt):
mocked_prompt.return_value = "hello"
result = get_name()
self.assertEqual(result, "hello")
Is InquirerPrompt compatible with kazhala/InquirerPy (upstream)?¶
Yes — InquirerPrompt is designed to be a drop-in replacement for the upstream InquirerPy package.
The import name is unchanged: import InquirerPy works exactly the same as before.
Simply replace your pip install InquirerPy with pip install InquirerPrompt and nothing else needs to change.
# Before (upstream, now unmaintained)
pip install InquirerPy
# After (this fork, actively maintained)
pip install InquirerPrompt
# Your code stays exactly the same
from InquirerPy import prompt, inquirer
Our goal is to maintain full backwards-compatibility with upstream InquirerPy 0.3.4 (the last upstream release) for as long as possible.
Any intentional API changes will be clearly documented in the changelog and in the Compatibility Report.
See the Compatibility Report for a detailed API surface comparison between this fork and the upstream release.