-
Notifications
You must be signed in to change notification settings - Fork 369
Description
Problem
When running pytest commands, e.g., fill:
uv run fill tests/istanbul/eip1344_chainid/test_chainid.py::test_chainid --output=/tmp/fixtures --clean --fork=Osaka
the following warning appears:
PytestAssertRewriteWarning: Module already imported so cannot be rewritten: execution_testing.cli.pytest_commands.plugins.custom_logging.plugin_logging
The following was generated by Claude, I think it's correct.
Root Cause
The warning occurs due to an architectural issue where core library code imports from a pytest plugin:
- Pytest loads
conftest.pyfiles before registering plugins from the ini file packages/testing/src/conftest.py:8imports fromexecution_testing.client_clis- This triggers an import chain:
client_clis/__init__.py→cli_types.py:20cli_types.py→custom_loggingpackagecustom_logging/__init__.py→plugin_logging.py
- When pytest later tries to register
custom_logging.plugin_loggingas a plugin, the module is already loaded, so pytest cannot apply assertion rewriting
The issue is that core library modules (execution_testing.client_clis, execution_testing.specs, execution_testing.test_types, etc.) import from execution_testing.cli.pytest_commands.plugins.custom_logging, creating a dependency from the library into a pytest plugin.
Impact
The warning is functionally harmless - it only means that assert statements in plugin_logging.py won't have pytest's enhanced error messages. All functionality works correctly.
Solution
Refactor the logging functionality out of the pytest plugin into a standalone module:
Implementation Steps
-
Create a new logging module separate from pytest plugins:
packages/testing/src/execution_testing/logging/ ├── __init__.py ├── logger.py (contains EESTLogger, ColorFormatter, etc.) └── levels.py (contains VERBOSE_LEVEL, FAIL_LEVEL, LogLevel) -
Move logging code from
cli/pytest_commands/plugins/custom_logging/plugin_logging.pyto the new module -
Update imports in the following locations:
execution_testing/client_clis/cli_types.pyexecution_testing/client_clis/ethereum_cli.pyexecution_testing/rpc/rpc.pyexecution_testing/specs/state.pyexecution_testing/test_types/*.py- All pytest plugins that use the logging functionality
-
Keep the pytest plugin at
custom_logging/plugin_logging.pybut have it:- Import from the new standalone logging module
- Only contain pytest-specific hooks and configuration
-
Update the plugin registration in pytest ini files to point to the minimal pytest plugin wrapper