MCPcopy
hub / github.com/pytest-dev/pytest / _in_venv

Function _in_venv

src/_pytest/main.py:416–434  ·  view source on GitHub ↗

Attempt to detect if ``path`` is the root of a Virtual Environment by checking for the existence of the pyvenv.cfg file. [https://peps.python.org/pep-0405/] For regression protection we also check for conda environments that do not include pyenv.cfg yet -- https://github.com/conda/

(path: Path)

Source from the content-addressed store, hash-verified

414
415
416def _in_venv(path: Path) -> bool:
417 """Attempt to detect if ``path`` is the root of a Virtual Environment by
418 checking for the existence of the pyvenv.cfg file.
419
420 [https://peps.python.org/pep-0405/]
421
422 For regression protection we also check for conda environments that do not include pyenv.cfg yet --
423 https://github.com/conda/conda/issues/13337 is the conda issue tracking adding pyenv.cfg.
424
425 Checking for the `conda-meta/history` file per https://github.com/pytest-dev/pytest/issues/12652#issuecomment-2246336902.
426
427 """
428 try:
429 return (
430 path.joinpath("pyvenv.cfg").is_file()
431 or path.joinpath("conda-meta", "history").is_file()
432 )
433 except OSError:
434 return False
435
436
437def pytest_ignore_collect(collection_path: Path, config: Config) -> bool | None:

Callers 2

test__in_venvMethod · 0.90
pytest_ignore_collectFunction · 0.85

Calls

no outgoing calls

Tested by 1

test__in_venvMethod · 0.72