@@ -169,6 +169,17 @@ def pytest_runtestloop(session):
169
169
return True
170
170
171
171
172
+ def _in_venv (path ):
173
+ """Attempts to detect if ``path`` is the root of a Virtual Environment by
174
+ checking for the existence of the appropriate activate script"""
175
+ bindir = path .join ('Scripts' if sys .platform .startswith ('win' ) else 'bin' )
176
+ if not bindir .exists ():
177
+ return False
178
+ activates = ('activate' , 'activate.csh' , 'activate.fish' ,
179
+ 'Activate' , 'Activate.bat' , 'Activate.ps1' )
180
+ return any ([fname .basename in activates for fname in bindir .listdir ()])
181
+
182
+
172
183
def pytest_ignore_collect (path , config ):
173
184
ignore_paths = config ._getconftest_pathlist ("collect_ignore" , path = path .dirpath ())
174
185
ignore_paths = ignore_paths or []
@@ -179,11 +190,10 @@ def pytest_ignore_collect(path, config):
179
190
if py .path .local (path ) in ignore_paths :
180
191
return True
181
192
182
- invenv = py .path .local (sys .prefix ) == path
183
- allow_invenv = config .getoption ("collect_in_virtualenv" )
184
- if invenv and not allow_invenv :
193
+ allow_in_venv = config .getoption ("collect_in_virtualenv" )
194
+ if _in_venv (path ) and not allow_in_venv :
185
195
config .warn (RuntimeWarning ,
186
- 'Path "%s" appears to be a Python installation; skipping\n '
196
+ 'Path "%s" appears to be a Python virtual installation; skipping\n '
187
197
'Pass --collect-in-virtualenv to force collection of tests in "%s"\n '
188
198
'Use --ignore="%s" to silence this warning' % (path , path , path )
189
199
)
0 commit comments