Skip to content

[CI/Build] Do not abort test collection when pexpect is missing - #110

Open
GuoCheng24 wants to merge 1 commit into
ResearAI:mainfrom
GuoCheng24:fix-pytest-collection-abort
Open

[CI/Build] Do not abort test collection when pexpect is missing#110
GuoCheng24 wants to merge 1 commit into
ResearAI:mainfrom
GuoCheng24:fix-pytest-collection-abort

Conversation

@GuoCheng24

Copy link
Copy Markdown

CONTRIBUTING.md says to run tests with pytest. On a clean checkout that aborts before collecting anything:

tests/test_tui_e2e.py:18: in <module>
    import pexpect
E   ModuleNotFoundError: No module named 'pexpect'
!!!!!! Interrupted: 1 error during collection !!!!!!

pexpect is declared nowhere — not in pyproject.toml dependencies or extras, not in install.sh, not in uv.lock. Neither is pytest itself. The file was clearly meant to be skippable: line 23 is pytestmark = pytest.mark.skipif(shutil.which("script") is None, ...). But that mark is evaluated after the module import, so the import takes the whole suite down instead of skipping this one file — 56 test files for one optional dependency.

The change. pexpect = pytest.importorskip("pexpect"), which skips this module and leaves the rest of the suite collecting, plus a dev extra declaring the test-only dependencies.

Verified both directions with pexpect blocked at import:

before:  ERROR tests/test_tui_e2e.py — Interrupted: 1 error during collection
after:   no tests collected in 0.03s   (this file skipped, collection continues)

AI assistance: partial — the reproduction, the fix and the before/after verification were done by running pytest with the import blocked on a clean venv, then confirming the rest of the suite still collects.

tests/test_tui_e2e.py imports pexpect at module level, before the skipif mark
below it. pexpect is not declared in pyproject.toml, install.sh or uv.lock, so
on a clean checkout the 'pytest' command in CONTRIBUTING.md fails collection of
the whole suite instead of skipping this one file. Use importorskip and declare
the test-only dependencies in a dev extra.
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