Support venv detection on Windows with mingw Python
This commit is contained in:
parent
0ed2d79457
commit
142b2fa6cd
1
AUTHORS
1
AUTHORS
|
@ -454,6 +454,7 @@ Yusuke Kadowaki
|
||||||
Yutian Li
|
Yutian Li
|
||||||
Yuval Shimon
|
Yuval Shimon
|
||||||
Zac Hatfield-Dodds
|
Zac Hatfield-Dodds
|
||||||
|
Zach Snicker
|
||||||
Zachary Kneupper
|
Zachary Kneupper
|
||||||
Zachary OBrien
|
Zachary OBrien
|
||||||
Zhouxin Qiu
|
Zhouxin Qiu
|
||||||
|
|
|
@ -369,22 +369,11 @@ def pytest_runtestloop(session: Session) -> bool:
|
||||||
|
|
||||||
def _in_venv(path: Path) -> bool:
|
def _in_venv(path: Path) -> bool:
|
||||||
"""Attempt to detect if ``path`` is the root of a Virtual Environment by
|
"""Attempt to detect if ``path`` is the root of a Virtual Environment by
|
||||||
checking for the existence of the appropriate activate script."""
|
checking for the existence of the pyvenv.cfg file."""
|
||||||
bindir = path.joinpath("Scripts" if sys.platform.startswith("win") else "bin")
|
|
||||||
try:
|
try:
|
||||||
if not bindir.is_dir():
|
return path.joinpath("pyvenv.cfg").exists()
|
||||||
return False
|
|
||||||
except OSError:
|
except OSError:
|
||||||
return False
|
return False
|
||||||
activates = (
|
|
||||||
"activate",
|
|
||||||
"activate.csh",
|
|
||||||
"activate.fish",
|
|
||||||
"Activate",
|
|
||||||
"Activate.bat",
|
|
||||||
"Activate.ps1",
|
|
||||||
)
|
|
||||||
return any(fname.name in activates for fname in bindir.iterdir())
|
|
||||||
|
|
||||||
|
|
||||||
def pytest_ignore_collect(collection_path: Path, config: Config) -> bool | None:
|
def pytest_ignore_collect(collection_path: Path, config: Config) -> bool | None:
|
||||||
|
|
|
@ -152,20 +152,8 @@ class TestCollectFS:
|
||||||
assert "test_notfound" not in s
|
assert "test_notfound" not in s
|
||||||
assert "test_found" in s
|
assert "test_found" in s
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
def test_ignored_virtualenvs(self, pytester: Pytester) -> None:
|
||||||
"fname",
|
ensure_file(pytester.path / "virtual" / "pyvenv.cfg")
|
||||||
(
|
|
||||||
"activate",
|
|
||||||
"activate.csh",
|
|
||||||
"activate.fish",
|
|
||||||
"Activate",
|
|
||||||
"Activate.bat",
|
|
||||||
"Activate.ps1",
|
|
||||||
),
|
|
||||||
)
|
|
||||||
def test_ignored_virtualenvs(self, pytester: Pytester, fname: str) -> None:
|
|
||||||
bindir = "Scripts" if sys.platform.startswith("win") else "bin"
|
|
||||||
ensure_file(pytester.path / "virtual" / bindir / fname)
|
|
||||||
testfile = ensure_file(pytester.path / "virtual" / "test_invenv.py")
|
testfile = ensure_file(pytester.path / "virtual" / "test_invenv.py")
|
||||||
testfile.write_text("def test_hello(): pass", encoding="utf-8")
|
testfile.write_text("def test_hello(): pass", encoding="utf-8")
|
||||||
|
|
||||||
|
@ -179,23 +167,11 @@ class TestCollectFS:
|
||||||
result = pytester.runpytest("virtual")
|
result = pytester.runpytest("virtual")
|
||||||
assert "test_invenv" in result.stdout.str()
|
assert "test_invenv" in result.stdout.str()
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
"fname",
|
|
||||||
(
|
|
||||||
"activate",
|
|
||||||
"activate.csh",
|
|
||||||
"activate.fish",
|
|
||||||
"Activate",
|
|
||||||
"Activate.bat",
|
|
||||||
"Activate.ps1",
|
|
||||||
),
|
|
||||||
)
|
|
||||||
def test_ignored_virtualenvs_norecursedirs_precedence(
|
def test_ignored_virtualenvs_norecursedirs_precedence(
|
||||||
self, pytester: Pytester, fname: str
|
self, pytester: Pytester
|
||||||
) -> None:
|
) -> None:
|
||||||
bindir = "Scripts" if sys.platform.startswith("win") else "bin"
|
|
||||||
# norecursedirs takes priority
|
# norecursedirs takes priority
|
||||||
ensure_file(pytester.path / ".virtual" / bindir / fname)
|
ensure_file(pytester.path / ".virtual" / "pyvenv.cfg")
|
||||||
testfile = ensure_file(pytester.path / ".virtual" / "test_invenv.py")
|
testfile = ensure_file(pytester.path / ".virtual" / "test_invenv.py")
|
||||||
testfile.write_text("def test_hello(): pass", encoding="utf-8")
|
testfile.write_text("def test_hello(): pass", encoding="utf-8")
|
||||||
result = pytester.runpytest("--collect-in-virtualenv")
|
result = pytester.runpytest("--collect-in-virtualenv")
|
||||||
|
@ -204,27 +180,13 @@ class TestCollectFS:
|
||||||
result = pytester.runpytest("--collect-in-virtualenv", ".virtual")
|
result = pytester.runpytest("--collect-in-virtualenv", ".virtual")
|
||||||
assert "test_invenv" in result.stdout.str()
|
assert "test_invenv" in result.stdout.str()
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
def test__in_venv(self, pytester: Pytester) -> None:
|
||||||
"fname",
|
|
||||||
(
|
|
||||||
"activate",
|
|
||||||
"activate.csh",
|
|
||||||
"activate.fish",
|
|
||||||
"Activate",
|
|
||||||
"Activate.bat",
|
|
||||||
"Activate.ps1",
|
|
||||||
),
|
|
||||||
)
|
|
||||||
def test__in_venv(self, pytester: Pytester, fname: str) -> None:
|
|
||||||
"""Directly test the virtual env detection function"""
|
"""Directly test the virtual env detection function"""
|
||||||
bindir = "Scripts" if sys.platform.startswith("win") else "bin"
|
# no pyvenv.cfg, not a virtualenv
|
||||||
# no bin/activate, not a virtualenv
|
|
||||||
base_path = pytester.mkdir("venv")
|
base_path = pytester.mkdir("venv")
|
||||||
assert _in_venv(base_path) is False
|
assert _in_venv(base_path) is False
|
||||||
# with bin/activate, totally a virtualenv
|
# with pyvenv.cfg, totally a virtualenv
|
||||||
bin_path = base_path.joinpath(bindir)
|
base_path.joinpath("pyvenv.cfg").touch()
|
||||||
bin_path.mkdir()
|
|
||||||
bin_path.joinpath(fname).touch()
|
|
||||||
assert _in_venv(base_path) is True
|
assert _in_venv(base_path) is True
|
||||||
|
|
||||||
def test_custom_norecursedirs(self, pytester: Pytester) -> None:
|
def test_custom_norecursedirs(self, pytester: Pytester) -> None:
|
||||||
|
|
Loading…
Reference in New Issue