-
Notifications
You must be signed in to change notification settings - Fork 0
Timeout aligns with pytest #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,6 +57,8 @@ def _run_test_in_container( | |
| func: Any, # noqa: ANN401 | ||
| container_spec: ContainerSpec, | ||
| test_kwargs: dict[str, Any], | ||
| *, | ||
| sync_request_timeout: int = 30, | ||
| ) -> None: | ||
| """Run a test function inside a Docker container.""" | ||
| clean = _get_clean_func(func) | ||
|
|
@@ -68,7 +70,10 @@ def _run_test_in_container( | |
| .with_exposed_ports(RPYC_PORT) as container | ||
| ): | ||
| started = container.start() | ||
| remote_func = bootstrap_container(started).teleport(clean) | ||
| conn = bootstrap_container( | ||
| started, sync_request_timeout=sync_request_timeout | ||
| ) | ||
| remote_func = conn.teleport(clean) | ||
| remote_func(**test_kwargs) | ||
| elif isinstance(container_spec, BuildSpec): | ||
| with ( | ||
|
|
@@ -78,17 +83,37 @@ def _run_test_in_container( | |
| .with_exposed_ports(RPYC_PORT) as container, | ||
| ): | ||
| started = container.start() | ||
| remote_func = bootstrap_container(started).teleport(clean) | ||
| conn = bootstrap_container( | ||
| started, sync_request_timeout=sync_request_timeout | ||
| ) | ||
| remote_func = conn.teleport(clean) | ||
| remote_func(**test_kwargs) | ||
| elif isinstance(container_spec, FactorySpec): | ||
| with container_spec.factory(RPYC_PORT) as container: | ||
| remote_func = bootstrap_container(container).teleport(clean) | ||
| conn = bootstrap_container( | ||
| container, sync_request_timeout=sync_request_timeout | ||
| ) | ||
| remote_func = conn.teleport(clean) | ||
| remote_func(**test_kwargs) | ||
| else: | ||
| msg = "Invalid container specification." | ||
| raise InvalidContainerSpecError(msg) | ||
|
|
||
|
|
||
| def _get_timeout(pyfuncitem: Function) -> int: | ||
| """Read the pytest timeout marker, falling back to the ini default or 30s.""" | ||
| timeout_marker = pyfuncitem.get_closest_marker("timeout") | ||
| if timeout_marker and timeout_marker.args: | ||
| return int(timeout_marker.args[0]) | ||
| try: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Prompt for Agent |
||
| ini_val = pyfuncitem.config.getini("timeout") | ||
| except ValueError: | ||
| return 30 | ||
| if ini_val: | ||
| return int(ini_val) | ||
| return 30 | ||
|
|
||
|
|
||
| def pytest_pyfunc_call(pyfuncitem: Function) -> object | None: | ||
| """Intercept test execution for in_container-marked tests.""" | ||
| marker = pyfuncitem.get_closest_marker("in_container") | ||
|
|
@@ -100,5 +125,10 @@ def pytest_pyfunc_call(pyfuncitem: Function) -> object | None: | |
| argnames = pyfuncitem._fixtureinfo.argnames # noqa: SLF001 | ||
| test_kwargs = {arg: funcargs[arg] for arg in argnames} | ||
| container_spec = _resolve_container_spec(marker, funcargs) | ||
| _run_test_in_container(testfunction, container_spec, test_kwargs) | ||
| _run_test_in_container( | ||
| testfunction, | ||
| container_spec, | ||
| test_kwargs, | ||
| sync_request_timeout=_get_timeout(pyfuncitem), | ||
| ) | ||
| return True | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This helper only looks at positional marker args and coerces them to
int, which diverges from pytest-timeout’s documented behaviour:@pytest.mark.timeout(timeout=10)(keyword form) is ignored and you fall back to the ini/default.0.5) get truncated toward zero, so short floating timeouts ortimeout=0(the official way to disable) become a zero-second RPC limit.0meaning “no limit”, but when neither a marker nor ini entry is present you now force a 30‑second timeout.If the goal is to align with pytest, this needs to honour keyword arguments, keep the float precision, and treat
0/Noneas “no timeout” instead of enforcing an immediate or 30‑second cut-off.Prompt for Agent