ethereum / ethereum/execution-specs
Running `fill` generates `PytestAssertRewriteWarning` for `custom_logging` plugin
- Dominant language
- Python
- Stars
- 1.2k
- Forks
- 505
- Avg merge
- 2d 8h
- Merged PRs (30d)
- 106
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**:
1. Pytest loads `conftest.py` files **before** registering plugins from the ini file
2. `packages/testing/src/conftest.py:8` imports from `execution_testing.client_clis`
3. This triggers an import chain:
- `client_clis/__init__.py` → `cli_types.py:20`
- `cli_types.py` → `custom_logging` package
- `custom_logging/__init__.py` → `plugin_logging.py`
4. When pytest later tries to register `custom_logging.plugin_logging` as 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
1. **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)
```
2. **Move logging code** from `cli/pytest_commands/plugins/custom_logging/plugin_logging.py` to the new module
3. **Update imports** in the following locations:
- `execution_testing/client_clis/cli_types.py`
- `execution_testing/client_clis/ethereum_cli.py`
- `execution_testing/rpc/rpc.py`
- `execution_testing/specs/state.py`
- `execution_testing/test_types/*.py`
- All pytest plugins that use the logging functionality
4. **Keep the pytest plugin** at `custom_logging/plugin_logging.py` but have it:
- Import from the new standalone logging module
- Only contain pytest-specific hooks and configuration
5. **Update the plugin registration** in pytest ini files to point to the minimal pytest plugin wrapper
Contributor guide
Assessment
This issue has not been assessed yet.