pytest-dev / pytest-dev/pytest-xdist

Add setting to disable adding cwd to pythonpath

Open
#121 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.9k
Forks
287
Avg merge
9h 30m
Merged PRs (30d)
2

Description

Hello!

I'm trying to use pytest-xdist together with tox to test a python extension written with cython.

When I run tox, it creates a new virtualenv, compiles my project and installs it to ./.tox/.../site-packages/modulename so that there is a directory with source code (./project/modulename) and a directory with compiled python extensions (./project/.tox/.../site-packages/modulename):

./project
  |-setup.py
  |-modulename
  |  |-__init__.py
  |  |-extension.pyx
  |-...
  |-.tox
     |-python/.../site-packages
        |-modulename
           |-__init__.py
           |-extension.so

When running normally, there is ./project/.tox/python/.../site-packages in PYTHONPATH and there is no ./project in it so modulename from site-packages imported when testing.

However, xdist adds ./project to PYTHONPATH (before .tox/.../site-packages) which causes modulename from project root being imported instead of modulename from site-packages. And everything fails with ImportError because there are no .so files in that modulename from project root.

As I understand, the code that adds cwd to pythonpath is here and it seems like there is no way to control this.

I propose adding a setting (a cli parameter) to disable this behavior.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with xdist/remote.py around line 149, then trace how pytest-xdist registers and handles command-line options. Add a setting that controls whether the current working directory is added to PYTHONPATH, and verify with a tox plus pytest-xdist setup that disabling it imports the installed extension instead of the source directory.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli, testing
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.