fix(ci,tooling,test-types,test-forks): import ethereum lazily so xdist fill coverage measures it#3059
Open
danceratopz wants to merge 2 commits into
Open
fix(ci,tooling,test-types,test-forks): import ethereum lazily so xdist fill coverage measures it#3059danceratopz wants to merge 2 commits into
ethereum lazily so xdist fill coverage measures it#3059danceratopz wants to merge 2 commits into
Conversation
`base_types` and `test_types.trie` import `ethereum.crypto.hash.keccak256` at module level, so importing the test framework (the `fill` CLI and its plugins) imports the measured `ethereum` package immediately -- before a pytest-xdist worker starts its coverage session in `pytest_sessionstart`. Coverage then reports `ethereum` as `module-not-measured`, and under-counts it (the statement total is lower in every mode, not only under xdist). Import keccak256 lazily, at first use during collection / test execution, so the `ethereum` import happens while the worker's coverage session is active.
`ExecutionSpecsTransitionTool` imported `ethereum` and the EELS t8n (`T8N`, `ForkCache`, `create_parser`, `get_supported_forks`) at module level, and the `forks` plugin called `t8n.is_fork_supported()` from `pytest_configure`. Both pull the measured `ethereum` package into `sys.modules` before a pytest-xdist worker starts its coverage session, leaving it `module-not-measured` and under-counted. Defer the imports to first use: - build `ForkCache` lazily via a property and import `create_parser`/`T8N`/`get_supported_forks` inside the methods that use them; read the tool version via `importlib.metadata`. - compute the unsupported-fork set lazily (cached), from collection and the report header, which run after the worker's coverage session starts.
ethereum lazily so xdist fill coverage measures it
ethereum lazily so xdist fill coverage measures itethereum lazily so xdist fill coverage measures it
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## forks/amsterdam #3059 +/- ##
================================================
Coverage 93.22% 93.22%
================================================
Files 624 624
Lines 36926 36926
Branches 3377 3377
================================================
Hits 34424 34424
Misses 1708 1708
Partials 794 794
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
ethereum lazily so xdist fill coverage measures itethereum lazily so xdist fill coverage measures it
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🗒️ Description
This PR improves the coverage measurement for
ethereumand fixes the following warning that everyfilljob logs, once per pytest-xdist worker:Root cause
pytest-cov starts an xdist worker's coverage session late — in
pytest_sessionstart. Theexecution_testingframework, however, imports the measuredethereumpackage at import time, well before that, from four module locations:base_typesandtest_types.trieimportethereum.crypto.hash.keccak256at module level — executed as soon as thefillCLI and its plugins are imported;ExecutionSpecsTransitionToolimports the EELS t8n (T8N/ForkCache/create_parser/get_supported_forks/ethereum) at module level, and theforksplugin callst8n.is_fork_supported()frompytest_configure.So by the time a worker starts measuring,
ethereumis already insys.modules.pytest-cov'sCentral/DistMasterengines suppress this warning;DistWorkerdoes not — hence it surfaces only on xdist workers.Coverage impact
Pre-importing the source package also makes coverage under-countethereum— in every mode,-n 0and-n 1alike.On a small sample, deferring the import raises the measured statement total from 36,926 → 39,000 (+2,074 across 152 files). The xdist warning was the visible symptom of a measurement gap that affected all runs.Update: the ~2,074 figure above was a measurement error (the "baseline" was a dirty checkout). A same-checkout A/B shows the statement denominator is unchanged (39,000). The real effect is small and constant:
fillmeasures ~300 moreethereumstatements — the import-time/header lines of modules loaded before the worker's coverage starts — ≈304 on a narrow Frontier slice and ≈303 on a 2,709-test Frontier→Cancun run, so it does not scale with the test set. At <1% it rounds to a ~0% codecov diff (see comment).The fix
Defer all four
ethereumimports to first use, so they run after the worker's coverage session has started (collection / test execution / thetrylastreport header). Specifically: lazykeccak256imports; a lazyForkCacheproperty + in-function t8n imports +importlib.metadatafor the tool version; and a lazily-computed, cached unsupported-fork set. Nothing is silenced — nofilterwarnings, no--disable-warnings, nodisable_warnings.Results
module-not-measuredgone — verified on the minimal repro, repeated-n 4runs, and a 2,709-test Frontier→Cancun fill.-n 0and-n 1report identical coverage;fillmeasures ~300 moreethereumstatements (import-time lines) on the same 39,000-statement denominator — a constant <1% gain, not test-set-dependent.eels_base_coverage--cov-fail-under=85gate passes (91.45%).just staticclean.Alternative considered
A runner-only approach was prototyped (start coverage earlier via
COVERAGE_PROCESS_START+ a dedicatedcoverage_fill.cfgin theJustfile, dropping pytest-cov's--covand combining manually). It works, but we preferred fixing the source because it:--cov=ethereuminvocation, not just thejust fillrecipe (directpytest/fillruns,json-loader, IDE runs, contributors);coverage erase/combine/report/xmland a second coverage config to keep in sync withpyproject.toml;The prototype lives on a local branch
fix-coverage-warnings-start-coverage-earlier(currently based off the wrong base), kept only for reference.🔗 Related Issues or PRs
N/A.
✅ Checklist
just statictype(scope):.