MCPcopy Create free account
hub / github.com/pytest-dev/pytest / _in_venv

Function _in_venv

src/_pytest/main.py:355–372  ·  view source on GitHub ↗

Attempt to detect if ``path`` is the root of a Virtual Environment by checking for the existence of the appropriate activate script.

(path: Path)

Source from the content-addressed store, hash-verified

353
354
355def _in_venv(path: Path) -> bool:
356 """Attempt to detect if ``path`` is the root of a Virtual Environment by
357 checking for the existence of the appropriate activate script."""
358 bindir = path.joinpath("Scripts" if sys.platform.startswith("win") else "bin")
359 try:
360 if not bindir.is_dir():
361 return False
362 except OSError:
363 return False
364 activates = (
365 "activate",
366 "activate.csh",
367 "activate.fish",
368 "Activate",
369 "Activate.bat",
370 "Activate.ps1",
371 )
372 return any(fname.name in activates for fname in bindir.iterdir())
373
374
375def pytest_ignore_collect(collection_path: Path, config: Config) -> Optional[bool]:

Callers 2

test__in_venvMethod · 0.90
pytest_ignore_collectFunction · 0.85

Calls

no outgoing calls

Tested by 1

test__in_venvMethod · 0.72