Skip to content

Running fill generates PytestAssertRewriteWarning for custom_logging plugin #1676

@danceratopz

Description

@danceratopz

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__.pycli_types.py:20
    • cli_types.pycustom_logging package
    • custom_logging/__init__.pyplugin_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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-test-cli-fillArea: Tests Fill CLI—runs tests and generates fixtures (eg. `p/t/s/e/cli/pytest_commands/fill.py`)C-bugCategory: this is a bug, deviation, or other problemE-mediumExperience: of moderate difficulty

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions