Skip to content

Run pexpect tests on CI by default #12884

Open
@The-Compiler

Description

@The-Compiler
  • 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:

pytest/tox.ini

Line 79 in f373974

pexpect: pexpect>=4.8.0

  • 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():

pytest/src/_pytest/pytester.py

Lines 1508 to 1522 in f373974

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: selftestsa problem in the tests of pytest

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions