From 5a13d6f6a00a9ce11d940dcff33a2dec832df411 Mon Sep 17 00:00:00 2001 From: prezakhani <13303554+Pouyanpi@users.noreply.github.com> Date: Tue, 12 Nov 2024 08:51:58 +0100 Subject: [PATCH] fix(tests): mock PromptSession to prevent console error The tests in `tests/test_cli.py` and `tests/test_cli_migration.py` were failing with `NoConsoleScreenBufferError` due to `prompt_toolkit` expecting a Windows console but finding `xterm-256color` instead. This issue occurs in Windows GitHub runners when the runner is `windows-latest`. To resolve this, `PromptSession` is mocked globally before any tests are collected, preventing the error. This fix ensures the tests run successfully in all environments. Changes: - Added `conftest.py` to mock `PromptSession` globally. --- tests/conftest.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 tests/conftest.py diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 000000000..12fb06e89 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,22 @@ +# SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from unittest.mock import patch + +import pytest + + +def pytest_configure(config): + patch("prompt_toolkit.PromptSession", autospec=True).start()