Description
What's the problem this feature will solve?
Currently pytest checks platform depended paths in a directory to see if it might be a venv:
Lines 370 to 387 in 0ed2d79
This works fine with the official CPython releases, but the mingw Python on Windows uses the Unix layout, which looks like this, despite being on Windows:
$ tree -L 1 .venv
.venv
├── bin
├── include
├── lib
└── pyvenv.cfg
This results in pytest trying to collect tests in venv files by default.
Describe the solution you'd like
I can see three solutions to this:
-
Check for both bin/Scripts
-
First check for the existence of "pyvenv.cfg", which should be in every venv on every platform
-
Replace the current logic and just check for "pyvenv.cfg". "pyvenv.cfg" was introduced in Python 3.3 with the venv module, so it might be enough to assume it exists in every venv. Maybe I'm missing something though.
Note: I'm happy to create a PR for any of the above solutions.
Activity
CI: run pytest without arguments to avoid stdlib distutils being impo…
RonnyPfannschmidt commentedon Jun 28, 2024
the initial code was added in b32cfc8 about 7 years ago when python 2.6 was still supported
so as far as i'm aware there is no reason not to switch to this much simpler test - a pr would be appreciated
bluetech commentedon Jun 28, 2024
Agreed, as far as I know, checking for pyvenv.cfg is sufficient.
zachsnicker commentedon Jun 28, 2024
Hello!
I'm new to contributing to pytest. Can I take this up?
webknjaz commentedon Jun 28, 2024
@zachsnicker I think it's non-controversial enough, I'll assign you. Make sure to include test coverage for the patch in your pull request.
lazka commentedon Jun 28, 2024
Just to be safe I did some additional research, https://peps.python.org/pep-0405/ defines venvs and states "Thus, a Python virtual environment in its simplest form would consist of nothing more than a copy or symlink of the Python binary accompanied by a pyvenv.cfg file and a site-packages directory.". So it's safe to assume that every venv following the spec will contain a pyvenv.cfg.
For the external virtualenv package pyvenv.cfg was added in v20, released 4+ years ago, which is also in Ubuntu 20.04 for example.
So I think this is fine.
I also had a look at the code already, so I'm happy to review if wanted.
CI: run pytest without arguments to avoid stdlib distutils being impo…
Support venv detection on Windows with mingw Python (pytest-dev#12545)
pytest==8.3.1
collects tests from Python dependencies withinconda
environments (regression from8.2.2
) #12652Support venv detection on Windows with mingw Python (pytest-dev#12545)