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 5d2770c commit 4a7be3d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 1 addition & 2 deletions tests/block_tools.py
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
13 changes: 13 additions & 0 deletions tests/conftest.py
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,15 @@
# fixtures avoids the issue.


@pytest.hookimpl
def pytest_exception_interact(
node: Union[pytest.Item, pytest.Collector],
call: CallInfo[Any],
report: Union[CollectReport, TestReport],
) -> None:
pytest.exit("Cancelled by exception")


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

0 comments on commit 4a7be3d

Please sign in to comment.