diff --git a/news/7249.feature b/news/7249.feature new file mode 100644 index 00000000000..4548aa006e2 --- /dev/null +++ b/news/7249.feature @@ -0,0 +1 @@ +Raise error if --user and --target are used together in command diff --git a/src/pip/_internal/commands/install.py b/src/pip/_internal/commands/install.py index da652238987..df9681f8c1c 100644 --- a/src/pip/_internal/commands/install.py +++ b/src/pip/_internal/commands/install.py @@ -237,6 +237,9 @@ def __init__(self, *args, **kw): @with_cleanup def run(self, options, args): # type: (Values, List[Any]) -> int + if options.use_user_site and options.target_dir is not None: + raise CommandError("Can not combine '--user' and '--target'") + cmdoptions.check_install_build_global(options) upgrade_strategy = "to-satisfy-only" if options.upgrade: diff --git a/tests/functional/test_install.py b/tests/functional/test_install.py index a95b46741dd..1ea9db26e4b 100644 --- a/tests/functional/test_install.py +++ b/tests/functional/test_install.py @@ -847,6 +847,27 @@ def test_install_package_with_target(script): assert singlemodule_py in result.files_updated, str(result) +def test_install_package_to_usersite_with_target_must_fail(script): + """ + Test that installing package to usersite with target + must raise error + """ + target_dir = script.scratch_path / 'target' + result = script.pip_install_local( + '--user', '-t', target_dir, "simple==1.0", expect_error=True + ) + assert "Can not combine '--user' and '--target'" in result.stderr, ( + str(result) + ) + + result = script.pip_install_local( + '--user', '--target', target_dir, "simple==1.0", expect_error=True + ) + assert "Can not combine '--user' and '--target'" in result.stderr, ( + str(result) + ) + + def test_install_nonlocal_compatible_wheel(script, data): target_dir = script.scratch_path / 'target'