3
3
4
4
import os
5
5
from pathlib import Path
6
+ from pathlib import PurePath
6
7
import pprint
7
8
import shutil
8
9
import sys
@@ -152,8 +153,17 @@ def test_ignored_certain_directories(self, pytester: Pytester) -> None:
152
153
assert "test_notfound" not in s
153
154
assert "test_found" in s
154
155
155
- def test_ignored_virtualenvs (self , pytester : Pytester ) -> None :
156
- ensure_file (pytester .path / "virtual" / "pyvenv.cfg" )
156
+ known_environment_types = pytest .mark .parametrize (
157
+ "env_path" ,
158
+ [
159
+ pytest .param (PurePath ("pyvenv.cfg" ), id = "venv" ),
160
+ pytest .param (PurePath ("conda-meta" , "history" ), id = "conda" ),
161
+ ],
162
+ )
163
+
164
+ @known_environment_types
165
+ def test_ignored_virtualenvs (self , pytester : Pytester , env_path : PurePath ) -> None :
166
+ ensure_file (pytester .path / "virtual" / env_path )
157
167
testfile = ensure_file (pytester .path / "virtual" / "test_invenv.py" )
158
168
testfile .write_text ("def test_hello(): pass" , encoding = "utf-8" )
159
169
@@ -167,11 +177,12 @@ def test_ignored_virtualenvs(self, pytester: Pytester) -> None:
167
177
result = pytester .runpytest ("virtual" )
168
178
assert "test_invenv" in result .stdout .str ()
169
179
180
+ @known_environment_types
170
181
def test_ignored_virtualenvs_norecursedirs_precedence (
171
- self , pytester : Pytester
182
+ self , pytester : Pytester , env_path
172
183
) -> None :
173
184
# norecursedirs takes priority
174
- ensure_file (pytester .path / ".virtual" / "pyvenv.cfg" )
185
+ ensure_file (pytester .path / ".virtual" / env_path )
175
186
testfile = ensure_file (pytester .path / ".virtual" / "test_invenv.py" )
176
187
testfile .write_text ("def test_hello(): pass" , encoding = "utf-8" )
177
188
result = pytester .runpytest ("--collect-in-virtualenv" )
@@ -180,13 +191,14 @@ def test_ignored_virtualenvs_norecursedirs_precedence(
180
191
result = pytester .runpytest ("--collect-in-virtualenv" , ".virtual" )
181
192
assert "test_invenv" in result .stdout .str ()
182
193
183
- def test__in_venv (self , pytester : Pytester ) -> None :
194
+ @known_environment_types
195
+ def test__in_venv (self , pytester : Pytester , env_path : PurePath ) -> None :
184
196
"""Directly test the virtual env detection function"""
185
- # no pyvenv.cfg , not a virtualenv
197
+ # no env path , not a env
186
198
base_path = pytester .mkdir ("venv" )
187
199
assert _in_venv (base_path ) is False
188
- # with pyvenv.cfg , totally a virtualenv
189
- base_path .joinpath ("pyvenv.cfg" ). touch ( )
200
+ # with env path , totally a env
201
+ ensure_file ( base_path .joinpath (env_path ) )
190
202
assert _in_venv (base_path ) is True
191
203
192
204
def test_custom_norecursedirs (self , pytester : Pytester ) -> None :
0 commit comments