diff --git a/Makefile b/Makefile index 73d8adea8..86303680d 100644 --- a/Makefile +++ b/Makefile @@ -34,7 +34,7 @@ install_test: cd $(PY_SPEC_DIR); python3 -m venv venv; . venv/bin/activate; pip3 install -r requirements-testing.txt; test: $(PY_SPEC_ALL_TARGETS) - cd $(PY_SPEC_DIR); . venv/bin/activate; python -m pytest . + cd $(PY_SPEC_DIR); . venv/bin/activate; python -m pytest eth2spec citest: $(PY_SPEC_ALL_TARGETS) cd $(PY_SPEC_DIR); mkdir -p test-reports/eth2spec; . venv/bin/activate; python -m pytest --junitxml=test-reports/eth2spec/test_results.xml . diff --git a/test_generators/operations/main.py b/test_generators/operations/main.py index ab8f0a98a..88c302032 100644 --- a/test_generators/operations/main.py +++ b/test_generators/operations/main.py @@ -1,4 +1,4 @@ -from eth2spec.testing.block_processing import ( +from eth2spec.test.block_processing import ( test_process_attestation, test_process_attester_slashing, test_process_block_header, diff --git a/test_libs/pyspec/README.md b/test_libs/pyspec/README.md index df1834210..330972e77 100644 --- a/test_libs/pyspec/README.md +++ b/test_libs/pyspec/README.md @@ -46,8 +46,9 @@ The `-B` flag may be helpful to force-overwrite the `pyspec` output after you ma Run the tests: ``` -pytest --config=minimal +pytest --config=minimal eth2spec ``` +Note the package-name, this is to locate the tests. ## Contributing diff --git a/test_libs/pyspec/eth2spec/testing/__init__.py b/test_libs/pyspec/eth2spec/test/__init__.py similarity index 100% rename from test_libs/pyspec/eth2spec/testing/__init__.py rename to test_libs/pyspec/eth2spec/test/__init__.py diff --git a/test_libs/pyspec/eth2spec/testing/block_processing/__init__.py b/test_libs/pyspec/eth2spec/test/block_processing/__init__.py similarity index 100% rename from test_libs/pyspec/eth2spec/testing/block_processing/__init__.py rename to test_libs/pyspec/eth2spec/test/block_processing/__init__.py diff --git a/test_libs/pyspec/eth2spec/testing/block_processing/test_process_attestation.py b/test_libs/pyspec/eth2spec/test/block_processing/test_process_attestation.py similarity index 97% rename from test_libs/pyspec/eth2spec/testing/block_processing/test_process_attestation.py rename to test_libs/pyspec/eth2spec/test/block_processing/test_process_attestation.py index c162945f0..e65943c84 100644 --- a/test_libs/pyspec/eth2spec/testing/block_processing/test_process_attestation.py +++ b/test_libs/pyspec/eth2spec/test/block_processing/test_process_attestation.py @@ -9,14 +9,14 @@ from eth2spec.phase0.spec import ( get_current_epoch, process_attestation ) -from eth2spec.testing.helpers import ( +from eth2spec.test.helpers import ( build_empty_block_for_next_slot, get_valid_attestation, next_epoch, next_slot, ) -from eth2spec.testing.context import spec_state_test, expect_assertion_error +from eth2spec.test.context import spec_state_test, expect_assertion_error def run_attestation_processing(state, attestation, valid=True): diff --git a/test_libs/pyspec/eth2spec/testing/block_processing/test_process_attester_slashing.py b/test_libs/pyspec/eth2spec/test/block_processing/test_process_attester_slashing.py similarity index 96% rename from test_libs/pyspec/eth2spec/testing/block_processing/test_process_attester_slashing.py rename to test_libs/pyspec/eth2spec/test/block_processing/test_process_attester_slashing.py index 6c87324e7..957b9a9f0 100644 --- a/test_libs/pyspec/eth2spec/testing/block_processing/test_process_attester_slashing.py +++ b/test_libs/pyspec/eth2spec/test/block_processing/test_process_attester_slashing.py @@ -3,13 +3,13 @@ from eth2spec.phase0.spec import ( get_beacon_proposer_index, process_attester_slashing, ) -from eth2spec.testing.helpers import ( +from eth2spec.test.helpers import ( get_balance, get_valid_attester_slashing, next_epoch, ) -from eth2spec.testing.context import spec_state_test, expect_assertion_error +from eth2spec.test.context import spec_state_test, expect_assertion_error def run_attester_slashing_processing(state, attester_slashing, valid=True): diff --git a/test_libs/pyspec/eth2spec/testing/block_processing/test_process_block_header.py b/test_libs/pyspec/eth2spec/test/block_processing/test_process_block_header.py similarity index 94% rename from test_libs/pyspec/eth2spec/testing/block_processing/test_process_block_header.py rename to test_libs/pyspec/eth2spec/test/block_processing/test_process_block_header.py index 278faa2c2..a176f7958 100644 --- a/test_libs/pyspec/eth2spec/testing/block_processing/test_process_block_header.py +++ b/test_libs/pyspec/eth2spec/test/block_processing/test_process_block_header.py @@ -6,12 +6,12 @@ from eth2spec.phase0.spec import ( advance_slot, process_block_header, ) -from eth2spec.testing.helpers import ( +from eth2spec.test.helpers import ( build_empty_block_for_next_slot, next_slot, ) -from eth2spec.testing.context import spec_state_test, expect_assertion_error +from eth2spec.test.context import spec_state_test, expect_assertion_error def prepare_state_for_header_processing(state): diff --git a/test_libs/pyspec/eth2spec/testing/block_processing/test_process_deposit.py b/test_libs/pyspec/eth2spec/test/block_processing/test_process_deposit.py similarity index 96% rename from test_libs/pyspec/eth2spec/testing/block_processing/test_process_deposit.py rename to test_libs/pyspec/eth2spec/test/block_processing/test_process_deposit.py index 9fbe77d40..fe2dae6a8 100644 --- a/test_libs/pyspec/eth2spec/testing/block_processing/test_process_deposit.py +++ b/test_libs/pyspec/eth2spec/test/block_processing/test_process_deposit.py @@ -4,7 +4,7 @@ from eth2spec.phase0.spec import ( ZERO_HASH, process_deposit, ) -from eth2spec.testing.helpers import ( +from eth2spec.test.helpers import ( get_balance, build_deposit, prepare_state_and_deposit, @@ -12,7 +12,7 @@ from eth2spec.testing.helpers import ( pubkeys, ) -from eth2spec.testing.context import spec_state_test, expect_assertion_error +from eth2spec.test.context import spec_state_test, expect_assertion_error def run_deposit_processing(state, deposit, validator_index, valid=True): diff --git a/test_libs/pyspec/eth2spec/testing/block_processing/test_process_proposer_slashing.py b/test_libs/pyspec/eth2spec/test/block_processing/test_process_proposer_slashing.py similarity index 96% rename from test_libs/pyspec/eth2spec/testing/block_processing/test_process_proposer_slashing.py rename to test_libs/pyspec/eth2spec/test/block_processing/test_process_proposer_slashing.py index cf4867776..3bfb17062 100644 --- a/test_libs/pyspec/eth2spec/testing/block_processing/test_process_proposer_slashing.py +++ b/test_libs/pyspec/eth2spec/test/block_processing/test_process_proposer_slashing.py @@ -3,12 +3,12 @@ from eth2spec.phase0.spec import ( get_current_epoch, process_proposer_slashing, ) -from eth2spec.testing.helpers import ( +from eth2spec.test.helpers import ( get_balance, get_valid_proposer_slashing, ) -from eth2spec.testing.context import spec_state_test, expect_assertion_error +from eth2spec.test.context import spec_state_test, expect_assertion_error def run_proposer_slashing_processing(state, proposer_slashing, valid=True): diff --git a/test_libs/pyspec/eth2spec/testing/block_processing/test_process_transfer.py b/test_libs/pyspec/eth2spec/test/block_processing/test_process_transfer.py similarity index 97% rename from test_libs/pyspec/eth2spec/testing/block_processing/test_process_transfer.py rename to test_libs/pyspec/eth2spec/test/block_processing/test_process_transfer.py index e8f96a710..31b136cc2 100644 --- a/test_libs/pyspec/eth2spec/testing/block_processing/test_process_transfer.py +++ b/test_libs/pyspec/eth2spec/test/block_processing/test_process_transfer.py @@ -6,12 +6,12 @@ from eth2spec.phase0.spec import ( get_current_epoch, process_transfer, ) -from eth2spec.testing.helpers import ( +from eth2spec.test.helpers import ( get_valid_transfer, next_epoch, ) -from eth2spec.testing.context import spec_state_test, expect_assertion_error +from eth2spec.test.context import spec_state_test, expect_assertion_error def run_transfer_processing(state, transfer, valid=True): diff --git a/test_libs/pyspec/eth2spec/testing/block_processing/test_process_voluntary_exit.py b/test_libs/pyspec/eth2spec/test/block_processing/test_process_voluntary_exit.py similarity index 97% rename from test_libs/pyspec/eth2spec/testing/block_processing/test_process_voluntary_exit.py rename to test_libs/pyspec/eth2spec/test/block_processing/test_process_voluntary_exit.py index a25981e3b..1efc950e0 100644 --- a/test_libs/pyspec/eth2spec/testing/block_processing/test_process_voluntary_exit.py +++ b/test_libs/pyspec/eth2spec/test/block_processing/test_process_voluntary_exit.py @@ -6,12 +6,12 @@ from eth2spec.phase0.spec import ( get_current_epoch, process_voluntary_exit, ) -from eth2spec.testing.helpers import ( +from eth2spec.test.helpers import ( build_voluntary_exit, pubkey_to_privkey, ) -from eth2spec.testing.context import spec_state_test, expect_assertion_error +from eth2spec.test.context import spec_state_test, expect_assertion_error def run_voluntary_exit_processing(state, voluntary_exit, valid=True): diff --git a/test_libs/pyspec/eth2spec/test/conftest.py b/test_libs/pyspec/eth2spec/test/conftest.py new file mode 100644 index 000000000..dadb0d5d0 --- /dev/null +++ b/test_libs/pyspec/eth2spec/test/conftest.py @@ -0,0 +1,36 @@ +from eth2spec.phase0 import spec + +# We import pytest only when it's present, i.e. when we are running tests. +# The test-cases themselves can be generated without installing pytest. + +def module_exists(module_name): + try: + __import__(module_name) + except ImportError: + return False + else: + return True + + +def fixture(*args, **kwargs): + if module_exists("pytest"): + import pytest + return pytest.fixture(*args, **kwargs) + else: + def ignore(): + pass + return ignore + + +def pytest_addoption(parser): + parser.addoption( + "--config", action="store", default="minimal", help="config: make the pyspec use the specified configuration" + ) + + +@fixture(autouse=True) +def config(request): + config_name = request.config.getoption("--config") + from preset_loader import loader + presets = loader.load_presets('../../configs/', config_name) + spec.apply_constants_preset(presets) diff --git a/test_libs/pyspec/eth2spec/testing/context.py b/test_libs/pyspec/eth2spec/test/context.py similarity index 100% rename from test_libs/pyspec/eth2spec/testing/context.py rename to test_libs/pyspec/eth2spec/test/context.py diff --git a/test_libs/pyspec/eth2spec/testing/epoch_processing/__init__.py b/test_libs/pyspec/eth2spec/test/epoch_processing/__init__.py similarity index 100% rename from test_libs/pyspec/eth2spec/testing/epoch_processing/__init__.py rename to test_libs/pyspec/eth2spec/test/epoch_processing/__init__.py diff --git a/test_libs/pyspec/eth2spec/testing/epoch_processing/test_process_crosslinks.py b/test_libs/pyspec/eth2spec/test/epoch_processing/test_process_crosslinks.py similarity index 97% rename from test_libs/pyspec/eth2spec/testing/epoch_processing/test_process_crosslinks.py rename to test_libs/pyspec/eth2spec/test/epoch_processing/test_process_crosslinks.py index 2d4044baf..203978d29 100644 --- a/test_libs/pyspec/eth2spec/testing/epoch_processing/test_process_crosslinks.py +++ b/test_libs/pyspec/eth2spec/test/epoch_processing/test_process_crosslinks.py @@ -10,7 +10,7 @@ from eth2spec.phase0.spec import ( get_crosslink_deltas, process_crosslinks, ) -from eth2spec.testing.helpers import ( +from eth2spec.test.helpers import ( add_attestation_to_state, build_empty_block_for_next_slot, fill_aggregate_attestation, @@ -19,7 +19,7 @@ from eth2spec.testing.helpers import ( next_epoch, next_slot, ) -from eth2spec.testing.context import spec_state_test +from eth2spec.test.context import spec_state_test def run_process_crosslinks(state, valid=True): diff --git a/test_libs/pyspec/eth2spec/testing/epoch_processing/test_process_registry_updates.py b/test_libs/pyspec/eth2spec/test/epoch_processing/test_process_registry_updates.py similarity index 95% rename from test_libs/pyspec/eth2spec/testing/epoch_processing/test_process_registry_updates.py rename to test_libs/pyspec/eth2spec/test/epoch_processing/test_process_registry_updates.py index 8ba1436ff..970c30942 100644 --- a/test_libs/pyspec/eth2spec/testing/epoch_processing/test_process_registry_updates.py +++ b/test_libs/pyspec/eth2spec/test/epoch_processing/test_process_registry_updates.py @@ -4,11 +4,11 @@ from eth2spec.phase0.spec import ( get_current_epoch, is_active_validator, ) -from eth2spec.testing.helpers import ( +from eth2spec.test.helpers import ( next_epoch, ) -from eth2spec.testing.context import spec_state_test +from eth2spec.test.context import spec_state_test @spec_state_test diff --git a/test_libs/pyspec/eth2spec/testing/helpers.py b/test_libs/pyspec/eth2spec/test/helpers.py similarity index 100% rename from test_libs/pyspec/eth2spec/testing/helpers.py rename to test_libs/pyspec/eth2spec/test/helpers.py diff --git a/test_libs/pyspec/eth2spec/testing/test_finality.py b/test_libs/pyspec/eth2spec/test/test_finality.py similarity index 100% rename from test_libs/pyspec/eth2spec/testing/test_finality.py rename to test_libs/pyspec/eth2spec/test/test_finality.py diff --git a/test_libs/pyspec/eth2spec/testing/test_sanity.py b/test_libs/pyspec/eth2spec/test/test_sanity.py similarity index 100% rename from test_libs/pyspec/eth2spec/testing/test_sanity.py rename to test_libs/pyspec/eth2spec/test/test_sanity.py diff --git a/test_libs/pyspec/eth2spec/testing/utils.py b/test_libs/pyspec/eth2spec/test/utils.py similarity index 100% rename from test_libs/pyspec/eth2spec/testing/utils.py rename to test_libs/pyspec/eth2spec/test/utils.py diff --git a/test_libs/pyspec/tests/__init__.py b/test_libs/pyspec/tests/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/test_libs/pyspec/tests/conftest.py b/test_libs/pyspec/tests/conftest.py deleted file mode 100644 index 8b90ce3b0..000000000 --- a/test_libs/pyspec/tests/conftest.py +++ /dev/null @@ -1,17 +0,0 @@ -import pytest - -from eth2spec.phase0 import spec -from preset_loader import loader - - -def pytest_addoption(parser): - parser.addoption( - "--config", action="store", default="minimal", help="config: make the pyspec use the specified configuration" - ) - - -@pytest.fixture(autouse=True) -def config(request): - config_name = request.config.getoption("--config") - presets = loader.load_presets('../../configs/', config_name) - spec.apply_constants_preset(presets)