From 89c73582caf9dda84f237bd6d4986d4db7d11a2e Mon Sep 17 00:00:00 2001 From: John Still Date: Tue, 11 Jul 2017 11:52:16 -0500 Subject: [PATCH] ignore the active python installation unless told otherwise --- _pytest/main.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/_pytest/main.py b/_pytest/main.py index 1a6ba2781..5b6409664 100644 --- a/_pytest/main.py +++ b/_pytest/main.py @@ -70,6 +70,8 @@ def pytest_addoption(parser): group.addoption('--keepduplicates', '--keep-duplicates', action="store_true", dest="keepduplicates", default=False, help="Keep duplicate tests.") + group.addoption('--collect-in-virtualenv', action='store_true', + help="Collect tests in the current Python installation (default False)") group = parser.getgroup("debugconfig", "test session debugging and configuration") @@ -177,6 +179,16 @@ def pytest_ignore_collect(path, config): if py.path.local(path) in ignore_paths: return True + invenv = py.path.local(sys.prefix) == path + allow_invenv = config.getoption("collect_in_virtualenv") + if invenv and not allow_invenv: + config.warn(RuntimeWarning, + 'Path "%s" appears to be a Python installation; skipping\n' + 'Pass --collect-in-virtualenv to force collection of tests in "%s"\n' + 'Use --ignore="%s" to silence this warning' % (path, path, path) + ) + return True + # Skip duplicate paths. keepduplicates = config.getoption("keepduplicates") duplicate_paths = config.pluginmanager._duplicatepaths