Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make KeyboardInterrupt cancel pytest #10279

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions chia/util/full_block_utils.py
@@ -1,8 +1,9 @@
from typing import Optional, Callable
from typing import Callable, Optional

from chia.types.blockchain_format.program import SerializedProgram
from clvm_rs import serialized_length
from blspy import G1Element, G2Element
from clvm_rs import serialized_length

from chia.types.blockchain_format.program import SerializedProgram


def skip_list(buf: memoryview, skip_item: Callable[[memoryview], memoryview]) -> memoryview:
Expand Down
2 changes: 1 addition & 1 deletion chia/util/struct_stream.py
@@ -1,8 +1,8 @@
import io
import struct
from typing import Any, BinaryIO, SupportsInt, Type, TypeVar, Union
from typing_extensions import SupportsIndex, Protocol

from typing_extensions import Protocol, SupportsIndex

_T_StructStream = TypeVar("_T_StructStream", bound="StructStream")

Expand Down
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
14 changes: 14 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
Comment on lines +7 to +9
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like these may all be available in the public API instead of _pytest. pytest-dev/pytest#7469

Perhaps not applicable after checking above, but I expect isort might prefer these to be all together? If not we may want to adjust a setting for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the version of pytest I have they are not exposed under pytest. That was my first attempt

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't pay attention whether pre-commit ran isort for me or not. But it should have, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find I frequently have to explicitly run pre-commit run --all to have checks be run..

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Python 3.9.5 (default, Jun  3 2021, 15:18:23) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pytest
>>> pytest.__version__
'7.0.1'
>>> from pytest import CallInfo, CollectReport, TestReport
>>>

If you have latest pytest and it isn't working for you I would be curious to know. We could dig into that on keybase.

Suggested change
from _pytest.runner import CallInfo
from _pytest.runner import CollectReport
from _pytest.runner import TestReport
from pytest import CallInfo, CollectReport, TestReport

On the pre-commit, it's default is to only run on 'modified' files. I'm not sure the definition of that. I personally just manually run it with --all.


# 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
14 changes: 7 additions & 7 deletions tests/util/test_full_block_utils.py
@@ -1,23 +1,23 @@
import random

import pytest

from chia.util.full_block_utils import generator_from_block
from chia.types.full_block import FullBlock
from chia.util.ints import uint128, uint64, uint32, uint8
from benchmarks.utils import rand_bytes, rand_g1, rand_g2, rand_hash, rand_vdf, rand_vdf_proof, rewards
from chia.types.blockchain_format.foliage import Foliage, FoliageBlockData, FoliageTransactionBlock, TransactionsInfo
from chia.types.blockchain_format.pool_target import PoolTarget
from chia.types.blockchain_format.foliage import Foliage, FoliageTransactionBlock, TransactionsInfo, FoliageBlockData
from chia.types.blockchain_format.program import SerializedProgram
from chia.types.blockchain_format.proof_of_space import ProofOfSpace
from chia.types.blockchain_format.reward_chain_block import RewardChainBlock
from chia.types.blockchain_format.program import SerializedProgram
from chia.types.blockchain_format.slots import (
ChallengeChainSubSlot,
InfusedChallengeChainSubSlot,
RewardChainSubSlot,
SubSlotProofs,
)
from chia.types.end_of_slot_bundle import EndOfSubSlotBundle

from benchmarks.utils import rand_hash, rand_bytes, rewards, rand_g1, rand_g2, rand_vdf, rand_vdf_proof
from chia.types.full_block import FullBlock
from chia.util.full_block_utils import generator_from_block
from chia.util.ints import uint8, uint32, uint64, uint128

test_g2s = [rand_g2() for _ in range(10)]
test_g1s = [rand_g1() for _ in range(10)]
Expand Down