Skip to content

Commit

Permalink
test_cli: make it work even if the test is called interactively
Browse files Browse the repository at this point in the history
rather "work" (mind the quotes): If pyinquirer is working and this was
called "bare metal" (i.e., not via `pytest`), the `browse` tool
stopped to ask the user for input. Since this is undesireable for a
unit test, we now mock `sys.stdout.isatty()` to always return `False`.

Signed-off-by: Andreas Lauser <[email protected]>
Signed-off-by: Alexander Walz <[email protected]>
  • Loading branch information
andlaus committed Feb 13, 2024
1 parent 9f2e23a commit 9c7f239
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import unittest
from argparse import Namespace
from typing import List, Optional
from unittest.mock import MagicMock, patch

import odxtools.cli.compare as compare
import odxtools.cli.decode as decode
Expand Down Expand Up @@ -131,7 +132,10 @@ def test_compare_tool(self) -> None:
UtilFunctions.run_compare_tool(ecu_variants=["somersault_lazy", "somersault_assiduous"])

@unittest.skipIf(browse_import_failed, "importing the browse tool failed")
def test_browse_tool(self) -> None:
# browse is an interactive tool, so we need to mock a few
# functions to make PyInquirer reliably bail out
@patch("sys.stdout.isatty", return_value=False)
def test_browse_tool(self, pi_prompt: MagicMock) -> None:
browse_args = Namespace(pdx_file="./examples/somersault.pdx")
with self.assertRaises(SystemError):
# browse can only be run interactively
Expand Down

0 comments on commit 9c7f239

Please sign in to comment.