pytester tests that require pexpect are silently skipped if pexpect is unavailable:
|
pexpect = importorskip("pexpect", "3.0") |
- We default to not installing
pexpect even on CI, only having it as an optional dependency with a -pexpect factor:
- The only CI environment where we include that is a Python 3.8 one:
|
- name: "ubuntu-py38" |
|
python: "3.8" |
|
os: ubuntu-latest |
|
tox_env: "py38-lsof-numpy-pexpect" |
|
use_coverage: true |
Why is pexpect an optional factor at all? From what I can gather, that was introduced in bd8a2cc because "it doesn't install on Windows anymore" back in 2013.
Nowadays, it seems to be partially available for Windows, though not pexpect.spawn which we use for Pytester.spawn():
|
def spawn(self, cmd: str, expect_timeout: float = 10.0) -> pexpect.spawn: |
|
"""Run a command using pexpect. |
|
|
|
The pexpect child is returned. |
|
""" |
|
pexpect = importorskip("pexpect", "3.0") |
|
if hasattr(sys, "pypy_version_info") and "64" in platform.machine(): |
|
skip("pypy-64 bit not supported") |
|
if not hasattr(pexpect, "spawn"): |
|
skip("pexpect.spawn not available") |
|
logfile = self.path.joinpath("spawn.out").open("wb") |
|
|
|
child = pexpect.spawn(cmd, logfile=logfile, timeout=expect_timeout) |
|
self._request.addfinalizer(logfile.close) |
|
return child |
I think we should either:
- Figure out if we can change
Pytester in a backwards-compatible way to use the cross-platform PopenSpawn instead. Pexpect claims:
PopenSpawn is not a direct replacement for spawn. Many programs only offer interactive behaviour if they detect that they are running in a terminal. When run by PopenSpawn, they may behave differently.
- Or if not, at least install
pexpect unconditionally on Linux (and perhaps macOS) as part of our dev dependencies, using a environment marker (added in pip 6.0 in 2014, so that wasn't an option back when the tox factor was introduced).
pytestertests that requirepexpectare silently skipped ifpexpectis unavailable:pytest/src/_pytest/pytester.py
Line 1513 in f373974
pexpecteven on CI, only having it as an optional dependency with a-pexpectfactor:pytest/tox.ini
Line 79 in f373974
pytest/.github/workflows/test.yml
Lines 116 to 120 in f373974
Yet, we have 40 (!) selftests that use
pexpect- most notably, most of test_debugging.py (38 of 59 skipped)And that caused us to miss [Python 3.13.0b2]
test_pdb_used_outside_testandtest_pdb_used_in_generate_testsare failing with Python 3.13 #12497 on our own CIWhy is pexpect an optional factor at all? From what I can gather, that was introduced in bd8a2cc because "it doesn't install on Windows anymore" back in 2013.
Nowadays, it seems to be partially available for Windows, though not
pexpect.spawnwhich we use forPytester.spawn():pytest/src/_pytest/pytester.py
Lines 1508 to 1522 in f373974
I think we should either:
Pytesterin a backwards-compatible way to use the cross-platformPopenSpawninstead. Pexpect claims:pexpectunconditionally on Linux (and perhaps macOS) as part of our dev dependencies, using a environment marker (added in pip 6.0 in 2014, so that wasn't an option back when the tox factor was introduced).