Skip to content

Difference of sys.path between running py.test and testdir.runpytest #742

@pytestbot

Description

@pytestbot

Originally reported by: Daniel Hahler (BitBucket: blueyed, GitHub: blueyed)


I've noticed that pytest's runpytest method fails when pies2overrides is
installed in the virtualenv, which adds a reprlib.py file into site-packages.

While this is clearly an issue with
pies
, pytest is
triggering it by calling its script from this site-packages dir.

% virtualenv venv
% venv/bin/pip install pytest pies2overrides==2.6.5

# Simulate `testdir.runpytest`:
% venv/bin/python venv/lib/python3.4/site-packages/pytest.py

Maybe pytest could use another approach here to call itself?
And/or something like sys.path.pop(0) in the script?

I might be missing something here, of course, but it seems like the behaviour/setup of the Python path differs between running py.test and runpytest, which should be avoided.

Output:

% virtualenv venv
Using base prefix '/home/daniel/.pyenv/versions/3.4.3'
New python executable in venv/bin/python3.4
Also creating executable in venv/bin/python
Installing setuptools, pip...done.

% venv/bin/pip install pytest pies2overrides==2.6.5
Collecting pytest
  Using cached pytest-2.7.0.tar.gz
Collecting pies2overrides==2.6.5
  Using cached pies2overrides-2.6.5-py2.py3-none-any.whl
Collecting py>=1.4.25 (from pytest)
  Using cached py-1.4.27-py2.py3-none-any.whl
Collecting ipaddress (from pies2overrides==2.6.5)
  Using cached ipaddress-1.0.7.tar.gz
Installing collected packages: py, pytest, ipaddress, pies2overrides
  Running setup.py install for pytest
  Running setup.py install for ipaddress
Successfully installed ipaddress-1.0.7 pies2overrides-2.6.5 py-1.4.27 pytest-2.7.0

% venv/bin/python venv/lib/python3.4/site-packages/pytest.py
Traceback (most recent call last):
  File "venv/lib/python3.4/site-packages/pytest.py", line 9, in <module>
    import pytest
  File "/tmp/t/venv/lib/python3.4/site-packages/pytest.py", line 14, in <module>
    from _pytest.config import main, UsageError, _preloadplugins, cmdline
  File "/tmp/t/venv/lib/python3.4/site-packages/_pytest/config.py", line 2, in <module>
    import argparse
  File "/home/daniel/.pyenv/versions/3.4.3/lib/python3.4/argparse.py", line 86, in <module>
    import collections as _collections
  File "/tmp/t/venv/lib/python3.4/collections/__init__.py", line 17, in <module>
    from reprlib import recursive_repr as _recursive_repr
  File "/tmp/t/venv/lib/python3.4/site-packages/reprlib.py", line 3, in <module>
    from repr import *
ImportError: No module named 'repr'
shell returned 1

For reference, here's a similar issue where virtualenv is affected: pypa/virtualenv#671.


Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions