pytesttox

AttributeError: module 'py' has no attribute 'io' for tox for python


AttributeError: module 'py' has no attribute 'io'

Steps:

  1. clone Pytest

    git clone https://github.com/pytest-dev/pytest.git

  2. Run tox:

    tox

Result:

AttributeError: module 'py' has no attribute 'io'

everything else is working fine. What am I do wrong?


Solution

  • The py module used to have py.io but in py>=1.12.0 it was removed. Some parts of the pytest source code or plugins still rely on py.io, especially in older clones or test setups.

    Try:

    1: Pin the py version

    Edit the tox.ini or requirements.txt (depending on your setup) and add a version pin for py:

    [deps]

    py<1.12.0

    Or you can manually install the compatible version:

    pip install 'py<1.12.0'

    Then run tox again.

    2: Update your clone

    If you're cloning pytest's own repo, make sure you're on the latest commit:

    git pull origin main

    They may have already patched this issue in recent commits. Then re-run:

    tox

    3: Use a virtualenv and pip install editable

    Sometimes cloning and testing a package like pytest is easier with a manual virtualenv setup:

    python -m venv .venv

    source .venv/bin/activate

    pip install -e .[testing]

    pytest