Skip to content

Conversation

@markovejnovic
Copy link
Contributor

No description provided.

@mesa-dot-dev
Copy link

mesa-dot-dev bot commented Feb 9, 2026

Mesa Description

This PR introduces a fundamental change in how test functions are executed in the container. Instead of recompiling the test function's source code inside the container, we now use cloudpickle to serialize the function and its dependencies on the host and execute it via RPyC in the container.

This new approach automatically handles module-level dependencies like imports, constants, and helper functions, making it much easier to write tests that run in a container.

Key Changes:

  • Dependency Serialization: Added cloudpickle to serialize test functions, capturing their full closure and dependencies.
  • Execution Mechanism: Replaced the teleport-based source code transmission with a new run_pickled function that sends the serialized function to the container using RPyC for native execution.
  • Refactoring:
    • The in_container decorator and the core plugin logic in _plugin.py were simplified to use the new centralized run_pickled utility.
    • Removed the old _get_clean_func utility, as it's no longer needed.
  • Testing: Added a new test suite (test_cloudpickle.py) to explicitly verify that functions with various types of dependencies are serialized and executed correctly.
  • Documentation: The README.md has been completely rewritten to reflect the new, simpler workflow and updated API.

Description generated by Mesa. Update settings

Add cloudpickle as a dependency for serializing test functions to
containers instead of rpyc teleport. This enables closure and lambda
support.

- Add cloudpickle>=3.1.1 to pyproject.toml dependencies
- Install cloudpickle in container alongside rpyc and pytest
- Add run_pickled() helper that serializes a callable with cloudpickle,
  sends it to the container via rpyc, and executes it remotely
- Update version mismatch error message to reference pickle compatibility
@markovejnovic markovejnovic merged commit e5a7269 into main Feb 9, 2026
3 checks passed
Copy link

@mesa-dot-dev mesa-dot-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Performed full review of 9b8303a...203e039

Analysis

  1. Critical centralization risk: All execution paths now funnel through _container.run_pickled, creating a single point of failure where any import errors or serialization issues would block all consumers.

  2. Dependency vulnerability: The system now relies heavily on cloudpickle for serialization, introducing a new external dependency that must be properly bootstrapped in containers.

  3. Code organization concern: Helper routines for function rewriting (_make_picklable, _force_by_value) are embedded in _container rather than in a dedicated utility module, potentially mixing responsibilities.

  4. Implementation stability risk: The marker/decorator wrappers now act as thin delegators to shared implementation in _container, meaning their correctness depends on import-time availability of these shared components.

Tip

Help

Slash Commands:

  • /review - Request a full code review
  • /review latest - Review only changes since the last review
  • /describe - Generate PR description. This will update the PR body or issue comment depending on your configuration
  • /help - Get help with Mesa commands and configuration options

6 files reviewed | 3 comments | Edit Agent SettingsRead Docs

clone = types.FunctionType(
func.__code__,
clean_globals,
func.__name__,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

High

Callable is now imported only under TYPE_CHECKING, but this module doesn’t use from __future__ import annotations. The annotations in _make_picklable, _force_by_value, and run_pickled are therefore evaluated at import time, and Callable is undefined. Importing pytest_in_docker._container will immediately raise NameError: name 'Callable' is not defined, so none of the container helpers can be used. Please import Callable unconditionally (or enable postponed evaluation of annotations) before referencing it in runtime annotations.

Fix in Cursor • Fix in Claude

Prompt for Agent
Task: Address review feedback left on GitHub.
Repository: mesa-dot-dev/pytest-in-docker#5
File: pytest_in_docker/_container.py#L235
Action: Open this file location in your editor, inspect the highlighted code, and resolve the issue described below.

Feedback:
`Callable` is now imported only under `TYPE_CHECKING`, but this module doesn’t use `from __future__ import annotations`. The annotations in `_make_picklable`, `_force_by_value`, and `run_pickled` are therefore evaluated at import time, and `Callable` is undefined. Importing `pytest_in_docker._container` will immediately raise `NameError: name 'Callable' is not defined`, so none of the container helpers can be used. Please import `Callable` unconditionally (or enable postponed evaluation of annotations) before referencing it in runtime annotations.

import textwrap
from collections.abc import Callable
from typing import Any, ParamSpec, TypeVar, overload
from typing import TYPE_CHECKING, ParamSpec, TypeVar, overload
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

High

Callable was moved under TYPE_CHECKING, but this module doesn’t postpone annotation evaluation. The overloads and decorator signature (Callable[[Callable[P, T]], Callable[P, T]], etc.) are executed when the module imports, so Callable is missing at runtime and the import raises NameError. That prevents users from importing pytest_in_docker.in_container entirely. Please keep Callable as a real import (or add from __future__ import annotations) so the annotations can resolve.

Fix in Cursor • Fix in Claude

Prompt for Agent
Task: Address review feedback left on GitHub.
Repository: mesa-dot-dev/pytest-in-docker#5
File: pytest_in_docker/_decorator.py#L3
Action: Open this file location in your editor, inspect the highlighted code, and resolve the issue described below.

Feedback:
`Callable` was moved under `TYPE_CHECKING`, but this module doesn’t postpone annotation evaluation. The overloads and decorator signature (`Callable[[Callable[P, T]], Callable[P, T]]`, etc.) are executed when the module imports, so `Callable` is missing at runtime and the import raises `NameError`. That prevents users from importing `pytest_in_docker.in_container` entirely. Please keep `Callable` as a real import (or add `from __future__ import annotations`) so the annotations can resolve.


```python
from pytest_in_docker import in_container
import subprocess
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low

This sample now uses the marker form (@pytest.mark.in_container) but the snippet no longer imports pytest, so copying it verbatim raises NameError. Either add import pytest to this block or revert the example back to the decorator version to keep it self‑contained.

Fix in Cursor • Fix in Claude

Prompt for Agent
Task: Address review feedback left on GitHub.
Repository: mesa-dot-dev/pytest-in-docker#5
File: README.md#L65
Action: Open this file location in your editor, inspect the highlighted code, and resolve the issue described below.

Feedback:
This sample now uses the marker form (`@pytest.mark.in_container`) but the snippet no longer imports `pytest`, so copying it verbatim raises `NameError`. Either add `import pytest` to this block or revert the example back to the decorator version to keep it self‑contained.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant