pytest-dev / pytest-dev/pytest

Pytest seems to search and create files in site-packages directory when not prompted to

Open
#10,781 7 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

topic: rewrite type: enhancement
Dominant language
Python
Stars
14.5k
Forks
3.4k
Avg merge
2d 9h
Merged PRs (30d)
35

Description

It seems that if pytest is run in a development directory, it can create files in site-packages/.../__pycache__ which can cause modules to continue getting "imported" even when they are uninstalled.

Many packages use import X as proof of an X package is installed and available.

If you:

  1. Install an optional package
  2. Run pytest
  3. Uninstall the optional package

It can leave your environment in a broken state.

Your input on "why" this is happening would be appreciated.

I wrote out my explanation and reproducer https://github.com/conda-forge/cupy-feedstock/issues/188#issuecomment-1449217000

  • a detailed description of the bug or problem you are having
  • output of pip list from the virtual environment you are using
  • pytest and operating system versions
  • minimal example if possible

Contributor guide

Open the contributing guide

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 by reproducing the optional-package install, pytest run, uninstall, and subsequent import behavior described in the issue and linked reproducer. Inspect the resulting site-packages/.../pycache files and compare the environment before and after using the listed pytest, operating system, and pip details. Done means the cause is established and a concrete fix or mitigation is identified.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.