|
| 1 | +# Test Markers |
| 2 | + |
| 3 | +Test markers are used to categorize tests and to run specific subsets of tests. They are defined in the test files using the `pytest.mark` decorator. |
| 4 | + |
| 5 | +## Fork Markers |
| 6 | + |
| 7 | +These markers are used to specify the forks for which a test is valid. |
| 8 | + |
| 9 | +### pytest.mark.valid_from("FORK_NAME") |
| 10 | + |
| 11 | +This marker is used to specify the fork from which the test is valid. The test will not be filled for forks before the specified fork. |
| 12 | + |
| 13 | +```python |
| 14 | +import pytest |
| 15 | + |
| 16 | +@pytest.mark.valid_from("London") |
| 17 | +def test_something_only_valid_after_london(): |
| 18 | + pass |
| 19 | +``` |
| 20 | + |
| 21 | +In this example, the test will only be filled for the London fork and after, e.g. London, Paris, Shanghai, Cancun, etc. |
| 22 | + |
| 23 | +### pytest.mark.valid_until("FORK_NAME") |
| 24 | + |
| 25 | +This marker is used to specify the fork until which the test is valid. The test will not be filled for forks after the specified fork. |
| 26 | + |
| 27 | +```python |
| 28 | +import pytest |
| 29 | + |
| 30 | +@pytest.mark.valid_until("London") |
| 31 | +def test_something_only_valid_until_london(): |
| 32 | + pass |
| 33 | +``` |
| 34 | + |
| 35 | +In this example, the test will only be filled for the London fork and before, e.g. London, Berlin, Istanbul, etc. |
| 36 | + |
| 37 | +### pytest.mark.valid_at_transition_to("FORK_NAME") |
| 38 | + |
| 39 | +This marker is used to specify that a test is only meant to be filled at the transition to the specified fork. |
| 40 | + |
| 41 | +The test usually starts at the fork prior to the specified fork at genesis and at block 5 (for pre-merge forks) or at timestamp 15,000 (for post-merge forks) the fork transition occurs. |
| 42 | + |
| 43 | +## Fork Covariant Markers |
| 44 | + |
| 45 | +These markers are used in conjunction with the fork markers to automatically parameterize tests with values that are valid for the fork being tested. |
| 46 | + |
| 47 | +### pytest.mark.with_all_tx_types |
| 48 | + |
| 49 | +This marker is used to automatically parameterize a test with all transaction types that are valid for the fork being tested. |
| 50 | + |
| 51 | +```python |
| 52 | +import pytest |
| 53 | + |
| 54 | +@pytest.mark.with_all_tx_types |
| 55 | +@pytest.mark.valid_from("Berlin") |
| 56 | +def test_something_with_all_tx_types(tx_type): |
| 57 | + pass |
| 58 | +``` |
| 59 | + |
| 60 | +In this example, the test will be parameterized for parameter `tx_type` with values `[0, 1]` for fork Berlin, but with values `[0, 1, 2]` for fork London (because of EIP-1559). |
| 61 | + |
| 62 | +### pytest.mark.with_all_contract_creating_tx_types |
| 63 | + |
| 64 | +This marker is used to automatically parameterize a test with all contract creating transaction types that are valid for the fork being tested. |
| 65 | + |
| 66 | +This marker only differs from `pytest.mark.with_all_tx_types` in that it does not include transaction type 3 (Blob Transaction type) on fork Cancun and after. |
| 67 | + |
| 68 | +### pytest.mark.with_all_precompiles |
| 69 | + |
| 70 | +This marker is used to automatically parameterize a test with all precompiles that are valid for the fork being tested. |
| 71 | + |
| 72 | +```python |
| 73 | +import pytest |
| 74 | + |
| 75 | +@pytest.mark.with_all_precompiles |
| 76 | +@pytest.mark.valid_from("Shanghai") |
| 77 | +def test_something_with_all_precompiles(precompile): |
| 78 | + pass |
| 79 | +``` |
| 80 | + |
| 81 | +In this example, the test will be parameterized for parameter `precompile` with values `[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]` for fork Shanghai, but with values `[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]` for fork Cancun (because of EIP-4844). |
| 82 | + |
| 83 | +## Other Markers |
| 84 | + |
| 85 | +### pytest.mark.slow |
| 86 | + |
| 87 | +This marker is used to mark tests that are slow to run. These tests are not run during tox testing, and are only run when a release is being prepared. |
| 88 | + |
| 89 | +### pytest.mark.skip("reason") |
| 90 | + |
| 91 | +This marker is used to skip a test with a reason. |
| 92 | + |
| 93 | +```python |
| 94 | +import pytest |
| 95 | + |
| 96 | +@pytest.mark.skip("Not implemented") |
| 97 | +def test_something(): |
| 98 | + pass |
| 99 | +``` |
| 100 | + |
| 101 | +### pytest.mark.xfail("reason") |
| 102 | + |
| 103 | +This marker is used to mark a test as expected to fail. |
| 104 | + |
| 105 | +```python |
| 106 | +import pytest |
| 107 | + |
| 108 | +@pytest.mark.xfail("EVM binary doesn't support this opcode") |
| 109 | +def test_something(): |
| 110 | + pass |
| 111 | +``` |
0 commit comments