diff --git a/ethstaker_deposit/utils/terminal.py b/ethstaker_deposit/utils/terminal.py index f64febd0..1e23cbc5 100644 --- a/ethstaker_deposit/utils/terminal.py +++ b/ethstaker_deposit/utils/terminal.py @@ -1,4 +1,5 @@ import subprocess +import os import sys import shutil import click @@ -6,10 +7,13 @@ def clear_terminal() -> None: if sys.platform == 'win32': - try: - subprocess.call('cls', shell=True) - except Exception: + # Special-case for asyncio pytest on Windows + if os.getenv("IS_ASYNC_TEST") == "1": click.clear() + elif shutil.which('clear'): + subprocess.call(['clear']) + else: + os.system('cls') elif sys.platform == 'linux' or sys.platform == 'darwin': if shutil.which('tput'): subprocess.call(['tput', 'reset']) diff --git a/tests/test_cli/test_new_mnemonic.py b/tests/test_cli/test_new_mnemonic.py index f8206de7..0a447705 100644 --- a/tests/test_cli/test_new_mnemonic.py +++ b/tests/test_cli/test_new_mnemonic.py @@ -4,6 +4,7 @@ import sys import pytest +import inspect from click.testing import CliRunner from eth_utils import decode_hex @@ -20,6 +21,14 @@ from .helpers import clean_key_folder, get_permissions, get_uuid +@pytest.fixture(autouse=True) +def check_async(request): + if inspect.iscoroutinefunction(request.node.obj): + os.environ['IS_ASYNC_TEST'] = '1' + else: + os.environ['IS_ASYNC_TEST'] = '0' + + def test_new_mnemonic_bls_withdrawal(monkeypatch) -> None: # monkeypatch get_mnemonic def mock_get_mnemonic(language, words_path, entropy=None) -> str: