Filler Plugin¶
A pytest plugin to fill tests and generate JSON fixtures.
FixtureOutput
¶
Bases: BaseModel
Represents the output destination for generated test fixtures.
Source code in src/pytest_plugins/filler/fixture_output.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
|
directory: Path
property
¶
Return the actual directory path where fixtures will be written.
metadata_dir: Path
property
¶
Return metadata directory to store fixture meta files.
is_tarball: bool
property
¶
Return True if the output should be packaged as a tarball.
is_stdout: bool
property
¶
Return True if the fixture output is configured to be stdout.
shared_pre_alloc_folder_path: Path
property
¶
Return the path for shared pre-allocation state file.
strip_tarball_suffix(path)
staticmethod
¶
Strip the '.tar.gz' suffix from the output path.
Source code in src/pytest_plugins/filler/fixture_output.py
70 71 72 73 74 75 |
|
is_directory_empty()
¶
Check if the output directory is empty.
Source code in src/pytest_plugins/filler/fixture_output.py
77 78 79 80 81 82 |
|
is_directory_usable_for_phase()
¶
Check if the output directory is usable for the current phase.
Source code in src/pytest_plugins/filler/fixture_output.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
|
get_directory_summary()
¶
Return a summary of directory contents for error reporting.
Source code in src/pytest_plugins/filler/fixture_output.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
|
create_directories(is_master)
¶
Create output and metadata directories if needed.
If clean flag is set, remove and recreate the directory. Otherwise, verify the directory is empty before proceeding.
Source code in src/pytest_plugins/filler/fixture_output.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
|
create_tarball()
¶
Create tarball of the output directory if configured to do so.
Source code in src/pytest_plugins/filler/fixture_output.py
191 192 193 194 195 196 197 198 199 200 |
|
from_config(config)
classmethod
¶
Create a FixtureOutput instance from pytest configuration.
Source code in src/pytest_plugins/filler/fixture_output.py
202 203 204 205 206 207 208 209 210 211 212 |
|
Top-level pytest configuration file providing: - Command-line options, - Test-fixtures that can be used by all test cases, and that modifies pytest hooks in order to fill test specs for all tests and writes the generated fixtures to file.
calculate_post_state_diff(post_state, genesis_state)
¶
Calculate the state difference between post_state and genesis_state.
This function enables significant space savings in reorg fixtures by storing only the accounts that changed during test execution, rather than the full post-state which may contain thousands of unchanged shared accounts.
Returns an Alloc containing only the accounts that: - Changed between genesis and post state (balance, nonce, storage, code) - Were created during test execution (new accounts) - Were deleted during test execution (represented as None)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
post_state |
Alloc
|
Final state after test execution |
required |
genesis_state |
Alloc
|
Shared genesis pre-allocation state |
required |
Returns:
Type | Description |
---|---|
Alloc
|
Alloc containing only the state differences for efficient storage |
Source code in src/pytest_plugins/filler/filler.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
|
default_output_directory()
¶
Directory (default) to store the generated test fixtures. Defined as a function to allow for easier testing.
Source code in src/pytest_plugins/filler/filler.py
101 102 103 104 105 106 |
|
default_html_report_file_path()
¶
File path (default) to store the generated HTML test report. Defined as a function to allow for easier testing.
Source code in src/pytest_plugins/filler/filler.py
109 110 111 112 113 114 |
|
pytest_addoption(parser)
¶
Add command-line options to pytest.
Source code in src/pytest_plugins/filler/filler.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
|
pytest_sessionstart(session)
¶
Initialize session-level state.
Either initialize an empty shared pre-state container for phase 1 or load the shared pre-allocation state for phase 2 execution.
Source code in src/pytest_plugins/filler/filler.py
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
|
pytest_configure(config)
¶
Pytest hook called after command line options have been parsed and before test collection begins.
Couple of notes: 1. Register the plugin's custom markers and process command-line options.
Custom marker registration:
https://docs.pytest.org/en/7.1.x/how-to/writing_plugins.html#registering-custom-markers
@pytest.hookimpl(tryfirst=True)
is applied to ensure that this hook is called before the pytest-html plugin's pytest_configure to ensure that it uses the modifiedhtmlpath
option.
Source code in src/pytest_plugins/filler/filler.py
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 |
|
pytest_report_header(config)
¶
Add lines to pytest's console output header.
Source code in src/pytest_plugins/filler/filler.py
374 375 376 377 378 379 380 |
|
pytest_report_teststatus(report, config)
¶
Modify test results in pytest's terminal output.
We use this:
- To disable test session progress report if we're writing the JSON
fixtures to stdout to be read by a consume command on stdin. I.e.,
don't write this type of output to the console:
...x...
Source code in src/pytest_plugins/filler/filler.py
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 |
|
pytest_terminal_summary(terminalreporter, exitstatus, config)
¶
Modify pytest's terminal summary to emphasize that no tests were ran.
Emphasize that fixtures have only been filled; they must now be executed to actually run the tests.
Source code in src/pytest_plugins/filler/filler.py
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 |
|
pytest_metadata(metadata)
¶
Add or remove metadata to/from the pytest report.
Source code in src/pytest_plugins/filler/filler.py
457 458 459 |
|
pytest_html_results_table_header(cells)
¶
Customize the table headers of the HTML report table.
Source code in src/pytest_plugins/filler/filler.py
462 463 464 465 466 |
|
pytest_html_results_table_row(report, cells)
¶
Customize the table rows of the HTML report table.
Source code in src/pytest_plugins/filler/filler.py
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 |
|
pytest_runtest_makereport(item, call)
¶
Make each test's fixture json path available to the test report via user_properties.
This hook is called when each test is run and a report is being made.
Source code in src/pytest_plugins/filler/filler.py
501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 |
|
pytest_html_report_title(report)
¶
Set the HTML report title (pytest-html plugin).
Source code in src/pytest_plugins/filler/filler.py
533 534 535 |
|
evm_bin(request)
¶
Return configured evm tool binary path used to run t8n.
Source code in src/pytest_plugins/filler/filler.py
538 539 540 541 |
|
verify_fixtures_bin(request)
¶
Return configured evm tool binary path used to run statetest or blocktest.
Source code in src/pytest_plugins/filler/filler.py
544 545 546 547 548 549 550 |
|
t8n(request, evm_bin)
¶
Return configured transition tool.
Source code in src/pytest_plugins/filler/filler.py
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 |
|
do_fixture_verification(request, verify_fixtures_bin)
¶
Return True if evm statetest or evm blocktest should be ran on the generated fixture JSON files.
Source code in src/pytest_plugins/filler/filler.py
571 572 573 574 575 576 577 578 579 580 581 582 583 584 |
|
evm_fixture_verification(request, do_fixture_verification, evm_bin, verify_fixtures_bin)
¶
Return configured evm binary for executing statetest and blocktest commands used to verify generated JSON fixtures.
Source code in src/pytest_plugins/filler/filler.py
587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 |
|
base_dump_dir(request)
¶
Path to base directory to dump the evm debug output.
Source code in src/pytest_plugins/filler/filler.py
630 631 632 633 634 635 636 637 638 |
|
fixture_output(request)
¶
Return the fixture output configuration.
Source code in src/pytest_plugins/filler/filler.py
641 642 643 644 |
|
is_output_tarball(fixture_output)
¶
Return True if the output directory is a tarball.
Source code in src/pytest_plugins/filler/filler.py
647 648 649 650 |
|
output_dir(fixture_output)
¶
Return directory to store the generated test fixtures.
Source code in src/pytest_plugins/filler/filler.py
653 654 655 656 |
|
create_properties_file(request, fixture_output)
¶
Create ini file with fixture build properties in the fixture output directory.
Source code in src/pytest_plugins/filler/filler.py
659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 |
|
dump_dir_parameter_level(request, base_dump_dir, filler_path)
¶
Directory to dump evm transition tool debug output on a test parameter level.
Example with --evm-dump-dir=/tmp/evm: -> /tmp/evm/shanghai__eip3855_push0__test_push0__test_push0_key_sstore/fork_shanghai/
Source code in src/pytest_plugins/filler/filler.py
703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 |
|
get_fixture_collection_scope(fixture_name, config)
¶
Return the appropriate scope to write fixture JSON files.
See: https://docs.pytest.org/en/stable/how-to/fixtures.html#dynamic-scope
Source code in src/pytest_plugins/filler/filler.py
727 728 729 730 731 732 733 734 735 736 737 |
|
reference_spec(request)
¶
Pytest fixture that returns the reference spec defined in a module.
See get_ref_spec_from_module
.
Source code in src/pytest_plugins/filler/filler.py
740 741 742 743 744 745 746 747 748 749 |
|
fixture_collector(request, do_fixture_verification, evm_fixture_verification, filler_path, base_dump_dir, fixture_output)
¶
Return configured fixture collector instance used for all tests in one test module.
Source code in src/pytest_plugins/filler/filler.py
752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 |
|
filler_path(request)
¶
Return directory containing the tests to execute.
Source code in src/pytest_plugins/filler/filler.py
779 780 781 782 |
|
node_to_test_info(node)
¶
Return test info of the current node item.
Source code in src/pytest_plugins/filler/filler.py
785 786 787 788 789 790 791 792 |
|
commit_hash_or_tag()
¶
Cache the git commit hash or tag for the entire test session.
Source code in src/pytest_plugins/filler/filler.py
795 796 797 798 |
|
fixture_source_url(request, commit_hash_or_tag)
¶
Return URL to the fixture source.
Source code in src/pytest_plugins/filler/filler.py
801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 |
|
base_test_parametrizer(cls)
¶
Generate pytest.fixture for a given BaseTest subclass.
Implementation detail: All spec fixtures must be scoped on test function level to avoid leakage between tests.
Source code in src/pytest_plugins/filler/filler.py
829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 |
|
pytest_generate_tests(metafunc)
¶
Pytest hook used to dynamically generate test cases for each fixture format a given test spec supports.
Source code in src/pytest_plugins/filler/filler.py
960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 |
|
pytest_collection_modifyitems(config, items)
¶
Remove pre-Paris tests parametrized to generate hive type fixtures; these can't be used in the Hive Pyspec Simulator.
Replaces the test ID for state tests that use a transition fork with the base fork.
These can't be handled in this plugins pytest_generate_tests() as the fork parametrization occurs in the forks plugin.
Source code in src/pytest_plugins/filler/filler.py
1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 |
|
pytest_sessionfinish(session, exitstatus)
¶
Perform session finish tasks.
- Save shared pre-allocation state (phase 1)
- Remove any lock files that may have been created.
- Generate index file for all produced fixtures.
- Create tarball of the output directory if the output is a tarball.
Source code in src/pytest_plugins/filler/filler.py
1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 |
|
Pre-alloc specifically conditioned for test filling.
pytest_addoption(parser)
¶
Add command-line options to pytest.
Source code in src/pytest_plugins/filler/pre_alloc.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
|
AllocMode
¶
Bases: IntEnum
Allocation mode for the state.
Source code in src/pytest_plugins/filler/pre_alloc.py
79 80 81 82 83 |
|
Alloc
¶
Bases: Alloc
Allocation of accounts in the state, pre and post test execution.
Source code in src/pytest_plugins/filler/pre_alloc.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
|
__init__(*args, alloc_mode, contract_address_iterator, eoa_iterator, evm_code_type=None, **kwargs)
¶
Initialize allocation with the given properties.
Source code in src/pytest_plugins/filler/pre_alloc.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
|
__setitem__(address, account)
¶
Set account associated with an address.
Source code in src/pytest_plugins/filler/pre_alloc.py
113 114 115 116 117 |
|
code_pre_processor(code, *, evm_code_type)
¶
Pre-processes the code before setting it.
Source code in src/pytest_plugins/filler/pre_alloc.py
119 120 121 122 123 124 125 126 127 128 129 130 |
|
deploy_contract(code, *, storage=None, balance=0, nonce=1, address=None, evm_code_type=None, label=None)
¶
Deploy a contract to the allocation.
Warning: address
parameter is a temporary solution to allow tests to hard-code the
contract address. Do NOT use in new tests as it will be removed in the future!
Source code in src/pytest_plugins/filler/pre_alloc.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
|
fund_eoa(amount=None, label=None, storage=None, delegation=None, nonce=None)
¶
Add a previously unused EOA to the pre-alloc with the balance specified by amount
.
If amount is 0, nothing will be added to the pre-alloc but a new and unique EOA will be returned.
Source code in src/pytest_plugins/filler/pre_alloc.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
|
fund_address(address, amount)
¶
Fund an address with a given amount.
If the address is already present in the pre-alloc the amount will be added to its existing balance.
Source code in src/pytest_plugins/filler/pre_alloc.py
239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
|
empty_account()
¶
Add a previously unused account guaranteed to be empty to the pre-alloc.
This ensures the account has: - Zero balance - Zero nonce - No code - No storage
This is different from precompiles or system contracts. The function does not send any transactions, ensuring that the account remains "empty."
Returns:
Name | Type | Description |
---|---|---|
Address |
Address
|
The address of the created empty account. |
Source code in src/pytest_plugins/filler/pre_alloc.py
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
|
alloc_mode(request)
¶
Return allocation mode for the tests.
Source code in src/pytest_plugins/filler/pre_alloc.py
276 277 278 279 280 281 |
|
contract_start_address(request)
¶
Return starting address for contract deployment.
Source code in src/pytest_plugins/filler/pre_alloc.py
284 285 286 287 |
|
contract_address_increments(request)
¶
Return address increment for contract deployment.
Source code in src/pytest_plugins/filler/pre_alloc.py
290 291 292 293 |
|
sha256_from_string(s)
¶
Return SHA-256 hash of a string.
Source code in src/pytest_plugins/filler/pre_alloc.py
296 297 298 |
|
contract_address_iterator(request, contract_start_address, contract_address_increments)
¶
Return iterator over contract addresses with dynamic scoping.
Source code in src/pytest_plugins/filler/pre_alloc.py
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
|
eoa_by_index(i)
cached
¶
Return EOA by index.
Source code in src/pytest_plugins/filler/pre_alloc.py
319 320 321 322 |
|
eoa_iterator(request)
¶
Return iterator over EOAs copies with dynamic scoping.
Source code in src/pytest_plugins/filler/pre_alloc.py
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 |
|
evm_code_type(request)
¶
Return default EVM code type for all tests (LEGACY).
Source code in src/pytest_plugins/filler/pre_alloc.py
344 345 346 347 348 349 350 351 |
|
pre(alloc_mode, contract_address_iterator, eoa_iterator, evm_code_type)
¶
Return default pre allocation for all tests (Empty alloc).
Source code in src/pytest_plugins/filler/pre_alloc.py
354 355 356 357 358 359 360 361 362 363 364 365 366 367 |
|