Support venv detection on Windows with mingw Python · Issue #12544 · pytest-dev/pytest (original) (raw)
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:
def _in_venv(path: Path) -> bool: |
---|
"""Attempt to detect if ``path`` is the root of a Virtual Environment by |
checking for the existence of the appropriate activate script.""" |
bindir = path.joinpath("Scripts" if sys.platform.startswith("win") else "bin") |
try: |
if not bindir.is_dir(): |
return False |
except OSError: |
return False |
activates = ( |
"activate", |
"activate.csh", |
"activate.fish", |
"Activate", |
"Activate.bat", |
"Activate.ps1", |
) |
return any(fname.name in activates for fname in bindir.iterdir()) |
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.