Skip to content

Commit

Permalink
make KeyboardInterrupt cancel pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
arvidn committed Feb 17, 2022
1 parent 974e29c commit 8aeac7d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 1 addition & 2 deletions tests/block_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import random
import shutil
import ssl
import sys
import tempfile
import time
from argparse import Namespace
Expand Down Expand Up @@ -323,7 +322,7 @@ async def new_plot(

except KeyboardInterrupt:
shutil.rmtree(self.temp_dir, ignore_errors=True)
sys.exit(1)
raise

async def refresh_plots(self):
self.plot_manager.refresh_parameter.batch_size = (
Expand Down
14 changes: 14 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
import pytest_asyncio
import tempfile
from pathlib import Path
from typing import Union, Any

from _pytest.runner import CallInfo
from _pytest.runner import CollectReport
from _pytest.runner import TestReport

# TODO: tests.setup_nodes (which is also imported by tests.util.blockchain) creates a
# global BlockTools at tests.setup_nodes.bt. This results in an attempt to create
Expand All @@ -15,6 +19,16 @@
# fixtures avoids the issue.


@pytest.hookimpl
def pytest_exception_interact(
node: Union[pytest.Item, pytest.Collector],
call: CallInfo[Any],
report: Union[CollectReport, TestReport],
) -> None:
if call.excinfo is not None and isinstance(call.excinfo.value, KeyboardInterrupt):
pytest.exit("Cancelled by KeyboardInterrupt")


@pytest_asyncio.fixture(scope="function", params=[1, 2])
async def empty_blockchain(request):
"""
Expand Down

0 comments on commit 8aeac7d

Please sign in to comment.