Skip to content

testing: Drop cached remote module in test_remote_exec_module_is_removed - #442

Open
kraj wants to merge 1 commit into
pytest-dev:mainfrom
kraj:fix-module-is-removed-stale-import
Open

kraj wants to merge 1 commit into
pytest-dev:mainfrom
kraj:fix-module-is-removed-stale-import

Conversation

@kraj

@kraj kraj commented Nov 5, 2026

Copy link
Copy Markdown

test_remote_exec_module_is_removed is parametrized over the gateway fixtures. The first run imports remote from its tmp_path and then removes that directory, but the module stays in sys.modules. Every later parametrization gets the stale module back from import remote, whose source file is gone, so remote_exec() fails with:

OSError: could not get source code

Only the first parametrization passes; each one passes when run on its own:

$ python -m pytest testing/test_gateway.py -k module_is_removed
5 failed, 1 passed, 10 skipped, 350 deselected

Remove remote from sys.modules (via monkeypatch, so it is restored afterwards) before importing it, so each run imports the module it just wrote. With this change all 6 parametrizations pass (Python 3.14.9, pytest 9.2.0).

test_remote_exec_module_is_removed is parametrized over the gateway
fixtures. The first run imports "remote" from its tmp_path and then
removes that directory, but the module stays in sys.modules. Later
runs then get the stale module back from "import remote", whose source
file is gone, and remote_exec() fails with:

  OSError: could not get source code

Remove "remote" from sys.modules before importing it, so each run
imports the module it just wrote.

Signed-off-by: Khem Raj <raj.khem@gmail.com>

This branch has not been deployed

No deployments
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